Problem opening a form

Swap

New member
Joined
Jan 17, 2003
Messages
2
Hi,

Im trying to create a custom msn messenger in VB.net. For this Im using a library I found (http://www.msnfanatic.com/article.php?sid=29), and I based myself on an example wich was supplied to (in C# though). Loggin in works, and a few other functionalitys to, but by far not all.

The problem i am having now is that when the messenger-object generates a conversation, i want to open a new form. Opening this form with a button works great, but when i want to open it from the event (set of by the messenger object) the forms opens and simply doesnt respond anymore (stops reacting, to close it you get the stop program window).

the code i use to open the form is:

Code:
Private Sub conversationCreated(ByVal sender As messenger, ByVal e As ConversationEventArgs) Handles messenger.ConversationCreated
        If openConversatie() Then
            MessageBox.Show("Conversation form opened nicely")
        Else
            MessageBox.Show("Conversation form did not open nicely at all")
        End If
        newForm.acceptConversatie(sender, e.Conversation)
    End Sub

    Private Function openConversatie() As Boolean
        Try
            Dim newForm As FormConversatie = New FormConversatie()
            newForm.Show()
        Catch e As Exception
            Return False
        End Try
        Return True
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If openConversatie() Then
            MessageBox.Show("Conversation form opened nicely")
        Else
            MessageBox.Show("Conversation form did not open nicely at all")
        End If
    End Sub

However, since i doubt that the error is in this, i attached the entire file as well. I tried to give most of the variables english names, but sometimes there will be a dutch one in between. My humble apologies for that...

Dont worry about using the hotmail account supplied in the program to test this program. Its one I created to test this program with, so i could communicate between this account and my regular one (wich is the only one in the list). Please dont change the password to this account, I dont use it anyway and it would save me the trouble of making yet another one.


any help would be greatly appriciated
 
Last edited by a moderator:
I deleted your original attachment because it contained some binaries.

However, I did fix your problem, and I have attached a zip file with the working solution in. I tested it with my own MSN Messenger account and I was able to talk to and from it just fine.

Your problem was a threading issue. The event was being raised by the dotMSN dll on a different thread than your UI components. Its very important to have all UI components on the same thread, so you have to use the Control.Invoke method to invoke a delegate on the correct thread. You will see Ive done this in your main form, by defining a delegate and calling it with parameters.

All that was required then was to uncomment the code youd already written in your Conversatie form and it all worked.
 

Attachments

Thanks. Ive had VB.net as a course since spetember now and I havent even heard of threads (only in my Java course, last year, but thats waay different).

Anyway, thanks a lot...
 
Back
Top