Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
B

bbranded

@bbranded
About
Posts
63
Topics
21
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • What is the best method to figure out elapsed time in a BackgroundWorker thread?
    B bbranded

    Thanks very much! This is very far from perfect, but will give others a good starting point to address this issue. I'll open source the final project over at mbrownnyc.wordpress.com shortly.

        private void \_bw\_DoWork(object sender, DoWorkEventArgs e)
        {
            //break up and assign the arguments passed by the methods:
            string\[\] CommandArguments = e.Argument.ToString().Split('#');
    
            string TargetDirectory = CommandArguments\[0\];
            bool RecursivePlz = Boolean.Parse(CommandArguments\[1\]);
            string LogFilename = CommandArguments\[2\];
    
            ReadFiles(TargetDirectory, RecursivePlz, LogFilename);
    
        }
    
        public void ReadFiles(string TargetDirectory, bool RecursivePlz, string LogFilename)
        {
    
            
            //take readsize and divide it by 1048576 (1MB)...
            // calculate how many operations it takes to complete the read of 1MB
            int readsize = 65536;
            double ReadOpsPerMB = readsize / 1048576;
            //see "use the ReadOpsPerMB" below
    
            TargetDirectory = TargetDirectory.ToLower();
    
            //exclude dfsrprivate folders
            if (!TargetDirectory.Contains("dfsrprivate"))
            {
    
                //find the directory
                if (Directory.Exists(TargetDirectory))
                {
                    //find the files in this directory
                    string\[\] FileList = Directory.GetFiles(TargetDirectory);
    
                    int BytesReadInRound = 0;
    
                    //check files in this directory
                    foreach (string ffile in FileList)
                    {
    
                        FileInfo finfo = new FileInfo(ffile);
                        if (finfo.Exists)
                        {
                            //get the full file size
                            int SizeOfFile = Int32.Parse(finfo.Length.ToString());
    
                            //adjust filestream buffer to be larger than the readsize, this will not force a read, and allow us to count the enumerations
                            FileStream readStream = new FileStream(ffile, FileMode.Open, FileAccess.Read, FileShare.None, readsize + 1);
                            BinaryReader binReader = new BinaryReader(readStream);
    
                            string Status = "";
    
                            bool Readthefile = true;
    
                            try
                            {
    
    C# question performance

  • What is the best method to figure out elapsed time in a BackgroundWorker thread?
    B bbranded

    Thanks. I'll look into that direction to solve the problem as well.

    C# question performance

  • What is the best method to figure out elapsed time in a BackgroundWorker thread?
    B bbranded

    Oh please please, share your wisdom. It's torture that you're keeping it all to yourself.

    C# question performance

  • What is the best method to figure out elapsed time in a BackgroundWorker thread?
    B bbranded

    That's a great idea. I was thinking backward. The concern is cross-thread communication, and I think you addressed this. BackgroundWorker_ProgressChange() has access to the main thread, which includes all objects in the inclusive/root class, such as a class-wide variable to hold a value, and the Timer object and events. I still have the problem of accuracy, "left over" bytes when polling occurs. I'll get testing! Thanks very much, Matt

    modified on Wednesday, August 10, 2011 11:33 AM

    C# question performance

  • What is the best method to figure out elapsed time in a BackgroundWorker thread?
    B bbranded

    Hello, I am attempting to create a benchmarking software that reads the contents of files. I would like to report, every five seconds, the average speed per MB read, the speed in MB/sec. I don't think that calculating a TimeSpan will be the best method, as it will definitely be inaccurate overtime (increasing in inaccuracy). If I use a timer in the BackgroundWorker thread, how do I pass a variable to the ElapsedEventHandler that contains the amount of data read?

        private void timer\_Elapsed(object sender, ElapsedEventArgs e)
        {
            MessageBox.Show(AmountOfBytesRead);
        }
    
        public void ReadFiles(string TargetDirectory, bool RecursivePlz, string LogFilename)
        {
    
            DateTime StartOfReading = DateTime.Now;
    
            System.Timers.Timer timer = new System.Timers.Timer();
            timer = new System.Timers.Timer();
            timer.Elapsed += new ElapsedEventHandler(timer\_Elapsed);
            timer.Interval = 5000;
            timer.Start();
    
            ...
            //read some file(s) and record the amount of bytes read to a variable AmountOfBytesRead
    

    }

    Thanks, Matt

    C# question performance

  • How do I monitor bytes per second written or read from a directory (and sub-directories)?
    B bbranded

    My work around is to use process monitor by the sysinternals dudes. Then parse the data. With the proper filters in place, the log ("backing file") grows about 4MB/minute; which is manageable. Process Monitor has a feature called File Summary (http://www.pcmag.com/slideshow_viewer/0,3253,l%253D248743%2526a%253D248736%2526po%253D13,00.asp?p=n[^]) which will summarize exactly what I want. Now, I guess the question is, how does Process Monitor gather this information? It's likely via the processes; monitoring the process's handles and where they are reading and writing. For me, this method, using Process Monitor, will do. However, it would still be interesting to investigate further ways to actually ways to grab the handles and identify their I/O. Thanks, Matt

    C# question csharp dotnet

  • How do I monitor bytes per second written or read from a directory (and sub-directories)?
    B bbranded

    Hello, I wish to monitor bytes per second written or read from a directory. Is something like this revealed by .NET framework, similar to that of FileSystemWatcher? I am attempting to monitor I/O to the DfsrPrivate folder to better understand the I/O of the dfsr.exe process. Thanks very much, Matt

    C# question csharp dotnet

  • Console app: Take arguments as verbatim string aka how do I create a verbatim string list?
    B bbranded

    Thanks! Sounds good.

    C# question help

  • Console app: Take arguments as verbatim string aka how do I create a verbatim string list?
    B bbranded

    The following are the command line arguments: /path:"c:\Documents and Settings\mbrown\Desktop\securable.exe" /save:"c:\Documents and Settings\mbrown\Desktop\" The following code:

    try
    {
    Console.WriteLine(savepath + "~scrublbdy.tmp");
    streamer = File.CreateText(savepath + "~scrublbdy.tmp");
    streamer.WriteLine("All work and no play makes Jack a null toy.");
    streamer.Close();

                        File.Delete(savepath + "~scrublbdy.tmp");
    
                    }
                    catch (Exception err)
                    {
                        Console.WriteLine(err);
                        Environment.Exit(1);
    
                    }
    

    Produces the following error:

    C:\Documents and Settings\mbrown\My Documents\Visual Studio 2008\Projects\securable_buddy\Securable_Buddy\Securable_Budd
    y\bin\Release\Securable_Buddy.exe /path:"c:\Documents and Settings\mbrown\Desktop\securable.exe" /save:"c:\Documents and Settings\"

    c:\Documents and Settings"\~scrublbdy.tmp
    System.ArgumentException: Illegal characters in path.
    at System.IO.Path.CheckInvalidPathChars(String path)
    at System.IO.Path.GetFileName(String path)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileO
    ptions options)
    at System.IO.StreamWriter.CreateFile(String path, Boolean append)
    at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
    at System.IO.StreamWriter..ctor(String path, Boolean append)
    at System.IO.File.CreateText(String path)
    at Securable_Buddy.Program.HandleArgs(String[] args) in C:\Documents and Settings\mbrown\My Documents\Visual Studio 2
    008\Projects\securable_buddy\Securable_Buddy\Securable_Buddy\Program.cs:line 117

    Note c:\Documents and Settings"\~scrublbdy.tmp. The trailing \ is being treated as an escape character in the argument. So the "best" solution I can think of is making the arguments that are passed to the main() function be verbatim strings. Any idea how to modify the incoming args to the Main() function static void Main(string[] args) to make them literal? Thanks, Matt

    C# question help

  • Console app: Take arguments as verbatim string aka how do I create a verbatim string list?
    B bbranded

    Hello, I'm attempting to have a console program take a path as an argument. I have the following code executing:

    static void Main(string[] args)
    {
    HandleArgs(args);
    }

    public static void HandleArgs(string[] args)
    {
    foreach (string arg in args)
    {
    if (arg.Contains("/path:"))
    {
    string execpath = arg.Substring(6, arg.Length - 6);
    }
    }
    }

    What i'd like to do is to take the string[] args as it is passed to Main() as a verbatim string. The problem arises when the argument /path: is input as /path:"c:\documents and settings\". The string arg in args is not verbatim, and execpath is then c:\documents and settings\" not c:\documents and settings\ as desired. Another foreseeable situation is the the /path: argument is /path:""c:\documents and settings\", as I am attempting a condition to determine if the last character is a \ How can I take the string into string[] args passed to Main() as a a verbatim string. Thanks, Matt

    C# question help

  • [SQLite3] handling returned data from PRAGMA table_info("table_name") in C#?
    B bbranded

    Is there a given interface to the ODBC items:

    TABLE_CAT
    TABLE_SCHEM
    TABLE_NAME
    COLUMN_NAME
    DATA_TYPE
    TYPE_NAME
    COLUMN_SIZE
    BUFFER_LENGTH
    DECIMAL_DIGITS
    NUM_PREC_RADIX
    NULLABLE
    REMARKS
    COLUMN_DEF
    SQL_DATA_TYPE
    SQL_DATETIME_SUB
    CHAR_OCTET_LENGTH
    ORDINAL_POSITION
    IS_NULLABLE

    to only parse certain "fields?" Thanks for your time, Matt

    Database database sqlite csharp html debugging

  • [SQLite3] handling returned data from PRAGMA table_info("table_name") in C#?
    B bbranded

    Thanks! DbConnection class

    Database database sqlite csharp html debugging

  • [SQLite3] handling returned data from PRAGMA table_info("table_name") in C#?
    B bbranded

    Thanks! I will look into the DataTable class more. Perfect.

    Database database sqlite csharp html debugging

  • [SQLite3] handling returned data from PRAGMA table_info("table_name") in C#?
    B bbranded

    Hello, I'm attempting to query a list of tables from an SQLite3 database and have come across the query PRAGMA table_info("table_name") in the SQLite docs. Here is my code:

    OdbcConnection DbConnection;
    OdbcDataReader DbReader;

    DbConnection = new OdbcConnection("DSN=" + odbcConnName);

    DbConnection.Open();

    OdbcCommand DbCommand = DbConnection.CreateCommand();
    //check to make sure column names are present
    DbCommand.CommandText = ("PRAGMA table_info(bandwidth_records)");
    DbReader = DbCommand.ExecuteReader();

                while (DbReader.Read())
                {
                    Trace.WriteLine(DbReader\["type"\].ToString());
                }
    

    DbReader.Close();
    DbConnection.Close();

    However, DbReader.Read() is not returning true. Very weird. Any ideas? Thanks, Matt

    Database database sqlite csharp html debugging

  • Creating a Class that can be a list?
    B bbranded

    Thanks very much Luc. I will take a look into this. As for snap, this is of the type SnapShot as defined via the SnapShot class's SnapShot function? Thanks, Matt

    C# question com tutorial

  • Creating a Class that can be a list?
    B bbranded

    Hello, I'm a little lost as to how to write a class that will take in arguments from the .Add function of a List<>. With reference to this thread, I have written the following class.

     public class SnapShot
        {
            private DateTime m\_SnapShotDateTime;
    
            public DateTime SnapShotDateTime
            {
                get
                {
                    return m\_SnapShotDateTime;
                }
                set
                {
                    m\_SnapShotDateTime = value;
                }
    
            }
    
            private long m\_BPSAverage;
    
            public long BPSAverage
            {
                get
                {
                    return m\_BPSAverage;
                }
                set
                {
                    m\_BPSAverage = value;
                }
            }
    
            public SnapShot(DateTime snapshotdatetime, long bpsaverage)
            {
                m\_SnapShotDateTime = snapshotdatetime;
                m\_BPSAverage = bpsaverage;
            }
    
        }
    

    I have created a List and would like to use the .Add function to add "entries" for .SnapShot(DateTime snapshotdatetime, long bpsaverage).

          SnapShot LiveSnapshot;
          List LiveSnapshotList = new List();
    
          //LiveSnapshotList.Add();
    

    How do I properly write the class so that it handles the .Add function of the List? Or should I be calling .Add with some other overload value? Thanks, Matt

    C# question com tutorial

  • Do I need to create a struct?
    B bbranded

    Thanks for your reply. This hit on performance (array.resize()) is less than the (probable) lower performance of a List<>? However, if array.resize() was never called, an array would be more optimal?

    C# data-structures tutorial question

  • Do I need to create a struct?
    B bbranded

    I agree with your ideology. Thanks for explaining. When an array is re-sized, the data is actually copied/recreated? Are you sure about this?

    C# data-structures tutorial question

  • Do I need to create a struct?
    B bbranded

    Is there a performance hit when utilizing a List versus a class[array] (and dynamically sizing this array)?

    C# data-structures tutorial question

  • Do I need to create a struct?
    B bbranded

    Thanks! This will work for two items. What can I do if I want to store more items? Thanks, Matt

    C# data-structures tutorial question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups