This is really confusing me as I'm not doing anything with Strings.
This is the details the debugger gives back to me:
System.FormatException was unhandled Message=Input string was not in a correct format. Source=System.Windows.Forms StackTrace: at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous) at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args) at Receiver.Class1.CrossThreadAddControl(Control ControlToAdd, Control BaseControl) in C:\Users\Jonathan\Documents\Visual Studio 2010\Projects\Receiver\Receiver\Class1.vb:line 28 at Receiver.ContactList.AddContact(Contact user) in C:\Users\Jonathan\documents\visual studio 2010\Projects\Receiver\Receiver\ContactList.vb:line 25 at Receiver.Form1.MySub(IAsyncResult ar) in C:\Users\Jonathan\Documents\Visual Studio 2010\Projects\Receiver\Receiver\Form1.vb:line 45 at System.Net.LazyAsyncResult.Complete(IntPtr userToken) at System.Net.ContextAwareResult.CompleteCallback(Object state) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Net.ContextAwareResult.Complete(IntPtr userToken) at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken) at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) at System.Threading.IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped pOVERLAP) InnerException:
Basically there is a sub called AddContact in a usercontrol(ContactList) which takes 3 strings and puts them into a another USerControl (Contact) and then adds the Contact to the ContactList The Contact List is on the main form, and the AddContact Sub is started from a different thread which is why the Invoke thing is needed.
Public Class ContactList
Sub AddContact(ByVal user As Contact)
If Me.Controls.Count = 0 Then
user.Location = New Drawing.Point(0, 0)
Else
user.Location = New Drawing.Point(0, Me.Controls.Count * 20)
End If
user.Width = Me.Width
user.Displayname = user.Username
For Each UC As Control In Me.Controls
If TypeOf UC Is Contact Then
If CType(UC, Contact).Username = user.Username Then
user.Displayname = user.Username & "@" & user.PCname
End If
End If
Next
Class1.CrossThreadAddControl(user, Me)
End Sub
End Class
and it is the line with the 2 asterixes (not actaully in the code) which is apparently causing the problems
Shared Sub CrossThreadAddControl(ByVal ControlToAdd As Control, ByVal BaseControl As Control)
If BaseControl.InvokeRequired Then
Dim d As New AddUserD(AddressOf AddUser)
**BaseControl.Invoke(d, ControlToAdd, BaseControl)**
End If
End Sub
Delegate Sub AddUserD(ByVal ControlToAdd As Control, ByVal BaseControl As Control)
Shared Sub AddUser(ByVal ControlToAdd As Control, ByVal BaseControl As Control)
BaseControl.Controls.Add(ControlToAdd)
End Sub
So any Idea why it saying Input string was not in a correct format? (oh and if I catch the exception (with Try and Catch) and don't write anything in the catch section it just continues and it works properly without breaking.