Using the "Invoke" method from another form.

oXiDe

Member
Joined
Jun 24, 2009
Messages
12
Programming Experience
1-3
Hi Guys,

I've run into a bit of a problem.. I am unsure as to how many people know how "IRC" Servers work here but basically, i'll explain

We are re-creating an IRC Client we made for our Chat site in VB.NET originally vb6

We have serveral different forms but the main problme we are having at the moment is

FrmMain is where you login to the servers, it grabs your data from our MySQL database such as "Nick, Gender, Font" etc. Then proceeds with connection to IRC server on Raw 001 we know the connection to the IRC server has been established... so therefore we open up FrmAuth which in this case they can see roomlist etc. We are unable to get FrmAuth to load probably.

We originally had this working opening up FrmAuth before the connection to IRC server has been established.. This really is no good for us causes alot of errors etc.

So when we use just simply "me.show()" the form loads but freezes we tried doing

VB.NET:
 Me.Invoke(New Del(AddressOf me.show))
however, this didnt work in which I assume that is because the "FrmAuth" hasn't yet loaded the GUI thread therefore there is no Thread to invoke so we tried

VB.NET:
 FrmMain.Invoke(New Del(AddressOf me.show))

This didn't work either i assume you cannot access another forms Invoke method..??
we are receiving the error A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll which i assume has something to do with it but not quite sure..

So my question comes down to the fact of, how do we open up FrmAuth without it freezing? Is there a way to access the invoke method on another form?


Thank you
 
Hello.

Why not adding this function to the form itself?
VB.NET:
Public Class frmAuth
    Public Sub ShowInvoke()
        If Me.InvokeRequired Then
            Me.Invoke(New MethodInvoker(AddressOf Me.Show))
        Else
            Me.Show()
        End If
    End Sub
End Class

And then call frmAuth.Showinvoke().

Bobby
 
oXiDe said:
FrmMain.Invoke(New Del(AddressOf me.show))
I assume you are calling from a secondary thread and that FrmMain here refers to the default instance of a FrmMain form class, in which case it would not work because default forms are thread specific, a new thread would return a new instance of the form created in the secondary threads context. What you need is any reference to an existing control/form in main UI thread and use this to invoke the delegate/method on to the UI thread.
 
Robert....
That still did not work it used the "Else" which obviously means Invoke not required... and Frmauth Loads but freezes


Basically FrmMain logs in to our servers checks the User/Password it then proceeds to connecting to the IRC Server using

FrmAuth.ConnectToServer("Address", Port) therefore we have told the App to Connect to the IRC server however we have not told it to show frmAuth yet.
When we receive RAW 001 from the IRC server thats when we want FrmAuth to show.. If i use a simple Me.Show() method the form opens but freezes right there.


Thanks
 
No, Sorry, JohnH is right. Forms are very thread specific which means that they stick with the thread from which they were called.

Invoke das nothing more than 'pulling' the request other to the thread of the object. You'll either have to call the form in a new thread, or (if possible) open it from another form which is on the main thread.

Bobby
 
Back
Top