Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If the form simply opens and closes immediately, it is likely you have an unhandled exception inside your constructor code. WinForms has an annoying habit of swallowing exceptions like this. If you Google around about it you should find some more information on it. You may be able to view the contents of this exception (if I am right in thinking that's the cause) by going to <code>Debug &gt; Exceptions</code> and checking the box next to <strong>Common Language Runtime Exceptions</strong> under <strong>Thrown</strong>. This should break on all exceptions under that category.</p> <p>As for whether the timer runs on another thread or not, best way to check is to add <code>Thread.Sleep(...some large number...)</code> in your handler for the <code>Tick</code> event (when your form is running) and see if it freezes the form. If so, it is running on the same thread.</p> <p><strong>EDIT</strong></p> <p>I've just had a quick look on MSDN and this is what I found about the threading of the timers:</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx" rel="nofollow"><em>System.Windows.Forms.Timer:</em></a></p> <blockquote> <p>A Timer is used to raise an event at user-defined intervals. This Windows timer is designed for a single-threaded environment where UI threads are used to perform processing. It requires that the user code have a UI message pump available and always operate from the same thread, or marshal the call onto another thread.</p> </blockquote> <p><a href="http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx" rel="nofollow"><em>System.Threading.Thread.Timer</em></a></p> <blockquote> <p>Use a TimerCallback delegate to specify the method you want the Timer to execute. The timer delegate is specified when the timer is constructed, and cannot be changed. The method does not execute on the thread that created the timer; it executes on a ThreadPool thread supplied by the system.</p> </blockquote> <p>So if I am correct in my understanding; the <code>System.Windows.Forms.Timer</code> executes on the UI thread (so will freeze the UI if performing long operations on it) and the <code>System.Threading.Thread.Timer</code> executes on a different thread to the UI (so shouldn't freeze the UI if performing long operations on it).</p> <p><strong>Note: Just to clarify; I am not saying that the UI should be updated on another thread - instead, I am merely trying to illustrate the differences between the timers that had been noted. UI can only be updated on the UI thread. If long operations need to be performed without freezing the UI thread (that are independent of any UI elements), they can be performed on a separate thread and then the update of the UI can be invoked on the UI thread.</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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