You call String.Replace() repeatedly (See bullet 2). You're _sub_array() is called repeatedly and returns a 16 length byte, yet another memory and performance issue.This is not only a memory issue, but a performance one too (Reference Jon Skeet's article ) You're concatenating a string repeatedly.If you're loading the entire file into a byte, then you could have a memory issue and possibly throw an OutOfMemoryException.You don't mention what those problems are so here are a few guesses: So you've got working code for small files, but you face problems with large files. So yeah, do switch to a StringBuilder object as well. Strings are immutable, so each time you concatenate to the string, internally what's happening is that the whole string is being scrapped and a new one is being made with the additional text. If you get the hang of Threads and Tasks (which are different inside the machine but can be manipulated by similar developer tools) you will never want to render to the UI from the main thread again.ĮDIT: I left the string from your code as it was, but I agree with the comment suggesting StringBuilder instead. This may seem intimidating at first if you have never done it, but trust me. This will stop the data processing from "gumming up" the UI responsiveness. BeginInvoke doesn't access the control directly, so you can use it from the data processing thread to get text written to the control. Only the thread that made the control is allowed to access it directly. This is necessary when you run the data processing on a separate thread because if you try to access the textbox directly with that thread, Windows will complain about a cross-thread call. Also note the BeginInvoke with the richTextBox.Text work in a lambda expression. You'll need to add "using System.Threading" to get access to threads. Private void button1_Click(object sender, EventArgs e) So using your code snippet, make it look more like this: data. You could also use tasks instead of threads, either way. You are wiser to use a separate thread for the hex work and let the main thread focus on keeping your UI operating smoothly. However, if you need the entire file in memory at once, I think your main problem might be the "stickiness" that the program will experience while reading and converting data. As has been said in the comments, you should try to avoid reading in the entire file at once.
0 Comments
Leave a Reply. |