it's been a while sience i did threading.
i'm trying to remember how to do it, but i'm hitting something that i KNOW i forgot.
here's the error code:
here's the thread: (located in a module)
here's the basic parts of the form1:
what is this error, why am i getting it, how do i fix it?
Thanks :D
i'm trying to remember how to do it, but i'm hitting something that i KNOW i forgot.
here's the error code:
Code:
"System.InvalidOperationException:
An error occurred creating the form. See Exception.InnerException for details.
The error is:
ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.
---> System.Threading.ThreadStateException: ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.
at System.Windows.Forms.WebBrowserBase..ctor(String clsidString)
at System.Windows.Forms.WebBrowser..ctor()
at UN_Client.Form1.InitializeComponent() in E:\Users\John Doe\documents\visual studio 2010\Projects\UN Client\UN Client\Form1.Designer.vb:line 40
at UN_Client.Form1..ctor() in E:\Users\John Doe\documents\visual studio 2010\Projects\UN Client\UN Client\Form1.vb:line 27
--- End of inner exception stack trace ---
at UN_Client.My.MyProject.MyForms.Create__Instance__[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190
at UN_Client.My.MyProject.MyForms.get_Form1()
at UN_Client.UpdateHandler.ThreadTask() in E:\Users\John Doe\documents\visual studio 2010\Projects\UN Client\UN Client\UpdateHandler.vb:line 96here's the thread: (located in a module)
Code:
Private WorkerThread As Thread 'Create the worker thread
Private NewVal As Integer 'New Value of progress bar & textbox
Private StopThread As Boolean = True 'Boolean Value used to halt the endless loop
Public Sub doGetTime()
If StopThread = False Then
StopThread = True
Else
StopThread = False
WorkerThread = New Thread(AddressOf ThreadTask)
WorkerThread.IsBackground = True
WorkerThread.Start()
End If
End Sub
Private Sub ThreadTask()
Dim req As HttpWebRequest = HttpWebRequest.Create("http://waxystudios.com/UN/JustTime.php")
Dim res As HttpWebResponse
Dim HTML As String = " "
'-------Setting up headers------------
req.UserAgent = VERSIONSTRING
req.Referer = "http://waxystudios.com/UN/JustTime.php"
req.ContentType = "application/x-www-form-urlencoded" 'Form content type
req.Method = "POST" 'data will be send in POST method
' req.CookieContainer = CookieJar 'Setting cookies
'-------------------------------------
Dim sw As StreamWriter
Dim poststring = " "
Try
sw = New StreamWriter(req.GetRequestStream)
sw.Write(poststring)
sw.Close()
Catch ex As Exception
End Try
res = req.GetResponse()
Dim sr As StreamReader = New StreamReader(res.GetResponseStream())
Try
HTML = sr.ReadToEnd 'HTML as result
Catch ex As Exception
Dim tempinfo As String
tempinfo = ex.ToString
TopMostMessageBox.Show("ERROR 1 :" & tempinfo)
End Try
Try
sr.Close()
res.Close()
' Form1.TimeLabel.Text = HTML 'returns HTML result
Form1.TimeInfo = HTML
Catch ex As Exception
Dim tempinfo As String
tempinfo = ex.ToString
TopMostMessageBox.Show("ERROR 2: " & tempinfo)
End Try
End Subhere's the basic parts of the form1:
Code:
Public Class Form1
Public TimeInfo As String
'( GetTime() is called elsewhere in form1)
Private Sub GetTime()
doGetTime()
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
TimeLabel.Text = TimeInfo
End SubThanks :D