Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strike>You can add a <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx" rel="nofollow">Timer</a> object to your form. Start the timer on the form load, and in the timer <code>Tick</code> event, run your code that you have in the infinite loop.</p> <p>Note: DO NOT include the <code>while(true)</code> loop, just the code inside the loop. You really don't want an infinite loop in your GUI thread :)</strike></p> <p>EDIT<br> I still think you may need to consider a redesign of the app behavior, but this should be better than the Timer I suggested earlier</p> <p>A somewhat better approach to the Timer (which should take care of the UI lag issue) would be for you to add a <a href="http://www.albahari.com/threading/part3.aspx#_BackgroundWorker" rel="nofollow">BackgroundWorker</a> to your UI. Add a <code>DoWork</code> method similar to this:</p> <pre><code>void DoWork(object sender, DoWorkEventArgs e) { while(!_bw.CancellationPending) { // Do your socket connection stuff // you can either update some member variables and call // the progresschanged method or you can use a BeginIvoke call // to update the labels, you CANNOT update the labels in this method if (!_bw.CancellationPending) { // Checking the cancel pending before sleeping so that we don't sleep // while a cancel is pending. There are better ways to do this with // event handles, but this should get you off and running. Thread.Sleep(1000); } } e.Cancel = true; } </code></pre> <p>Note: If you were using .Net 4.0, you may want to consider using the task factory and a cancellation token rather than the BackgroundWorker, but either one should get you up and running.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload