How To Restore Form from a Timer.Elapsed Event Handler

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pbskat
    New Member
    • Aug 2010
    • 2

    How To Restore Form from a Timer.Elapsed Event Handler

    Hi all,

    I have an application that opens a form using frmWebQ.Show() and there it asks the user a question. Instead of replying immediately the user can choose to be reminded later (after a selectable time periods betwen 10 min and 30 days). When remind later is chosen the form activates a timer for the requested time period and minimizes itself to the task tray (Me.WindowState = FormWindowState .Minimized). Meanwhile the user can continue his work in the main form. After the time has elapsed the event handler (Timer.Elapsed( )) is activated and here the form should be restored to its original size again using Me.WindowState = FormWindowState .Normal.

    However, this generates the following exception (translated from German by Google): "Illegal cross-thread operation: access to the control frmWebQ was from a thread other than the thread in which it was created."

    Any hint, how to overcome that? Thanks in advance.
  • pbskat
    New Member
    • Aug 2010
    • 2

    #2
    OK, problem solved: Welcome to Billy's Belly Shop - again a uselessly confusing complexity. There are two different timer classes, obviously the difference is that one operates in a different thread:

    Private myTimer As System.Timers.T imer
    Private M2Timer As Windows.Forms.T imer

    The first one operates in a different thread, the elapsed event is named Elapsed. The second operates in the same thread and the elapsed event is named Tick...

    Comment

    Working...