How to not have UDP data to form from background thread crash the program?
-
Wednesday, November 09, 2011 2:20 AM
I have a background worker thread receiving UDP data from a server. The background thread wraps the data and pushes it to the UI thread via the Progress changed UserState. After receiving a bunch of data the program crashes. Here is a code snippet:private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; MonitorThread(worker); } private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { ob o = e.UserState as ob; AddRow(o.ip, o.port, o.data); }
Complete source can be found on my skydrive here: https://skydrive.live.com/redir.aspx?cid=12c3e7f9200ab518&resid=12C3E7F9200AB518!282
Click: TraceUtility.zip to download source.
I want to use the Dataset, because I also want to easily remove rows that do not want before saving.
If anyone can think of an easier/better and thread safe way to do this then let me know.
Thanks in advance.
- Edited by Bydia Wednesday, November 09, 2011 2:22 AM
All Replies
-
Saturday, September 22, 2012 8:19 AM
I couldn't download your source as it requires a password.
Anyway I am assuming that you are binding the data to a control so that you can see it as it comes in. Then you will have problems with the background thread changing things while the control is trying to access the data.
Rather than use DataSet, it would seem better to use ConcurrentQueue, which is thread safe.


