G
Guest
I seem to run into a Catch 22 problem updating forms from a second thread. I have only been able to get the Invoke() function to work when the form was displayed using Application.Run(TheForm). When using ShowDialog() to display the form the Invoke() function does not return until the form closes. However, The application loses focus if I use Application.Run(TheNextForm) after the first one is closed
The following code does not have the synchorization elements necessary to be rigorously correct but it demonstrates the problems I'm seeing even with proper synchronization. BTW, the forms are default created forms with MinimizeBox = False so I'm using the 'X' to close the form. I've tried lots of combinations of ShowDialog(frm) and Application.Run(frm) with one or the other problem occuring. Am I missing something
Thanks in advanc
Imports System.Threadin
Public Class FocusClas
Private Shared f As For
Public Shared Sub Main(
Dim f1 As Focus
Dim f2 As Focus
f1 = New Focus
Application.Run(f1
Dim th As New Thread(AddressOf UpdateLoop
th.Start(
D
f2 = New Focus
f = f
f2.ShowDialog() ' I've also tried Applicaiton.Run(f2
f1 = New Focus
f = f
f1.ShowDialog() ' I've also tried Applicaiton.Run(f1
Loo
End Su
Private Shared Sub UpdateLoop(
D
Thread.Sleep(500
On Error Resume Nex
f.Invoke(New EventHandler(AddressOf
UpdateItem)
On Error GoTo
Loo
End Su
Private Shared Sub UpdateItem(ByVal sender As Object,
ByVal e As EventArgs
f.Text = Format(Now, "hh:mm:ss"
End Su
End Clas
The following code does not have the synchorization elements necessary to be rigorously correct but it demonstrates the problems I'm seeing even with proper synchronization. BTW, the forms are default created forms with MinimizeBox = False so I'm using the 'X' to close the form. I've tried lots of combinations of ShowDialog(frm) and Application.Run(frm) with one or the other problem occuring. Am I missing something
Thanks in advanc
Imports System.Threadin
Public Class FocusClas
Private Shared f As For
Public Shared Sub Main(
Dim f1 As Focus
Dim f2 As Focus
f1 = New Focus
Application.Run(f1
Dim th As New Thread(AddressOf UpdateLoop
th.Start(
D
f2 = New Focus
f = f
f2.ShowDialog() ' I've also tried Applicaiton.Run(f2
f1 = New Focus
f = f
f1.ShowDialog() ' I've also tried Applicaiton.Run(f1
Loo
End Su
Private Shared Sub UpdateLoop(
D
Thread.Sleep(500
On Error Resume Nex
f.Invoke(New EventHandler(AddressOf
UpdateItem)
On Error GoTo
Loo
End Su
Private Shared Sub UpdateItem(ByVal sender As Object,
ByVal e As EventArgs
f.Text = Format(Now, "hh:mm:ss"
End Su
End Clas