My Computer Forum Computer Science Forum

Go Back   My Computer Forum > Computer Science Forum > Programming

Programming Programming Languages, Interpreters, and Compilers - Assembly, Declarative, Machine, Object Oriented, Iterative

LinkBack Thread Tools Display Modes
July 18th, 2009, 10:28 AM   #1
Joined: Dec 2008
Posts: 30
Visual Basic InvalidOperationException

I have a button with the following code:
    Private Sub BtnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUpdate.Click
    End Sub
And a BackgroundWorker with the following code:
    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Dim time As String = My.Computer.Clock.LocalTime.ToString
        If "Threats" = "Threats" Then
            Dim blank25 As String = "                         "
            Dim alphabet As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
            For Each l As String In alphabet
                For Each m As String In alphabet
                    My.Computer.FileSystem.WriteAllText(Form1.baseDir & "\FILES\DATABASE\Threat\" & l & m & ".txt", "DATABASE:THREATS", False) in BackgroundWorker1_DoWork
                    My.Computer.FileSystem.WriteAllText(Form1.baseDir & "\FILES\DATABASE\Threat\" & l & m & ".txt", vbNewLine & "Last update: " & time, True)
                    My.Computer.FileSystem.WriteAllText(Form1.baseDir & "\FILES\DATABASE\Threat\" & l & m & ".txt", vbNewLine & "THREAT ALIAS=============ID=======================", True)
                For Each link As Link In Spider("" & l, "<a href=" & Chr(34) & "/business/security_response/writeup.jsp?docid=", "</a>", True)
                    If link.Text.Length > 25 Then
                        link.Text = Microsoft.VisualBasic.Left(link.Text, 25)
                    End If
                    Dim linkText As String = link.Text & Microsoft.VisualBasic.Left(blank25, 25 - link.Text.Length)
                    Dim linkSite As String = link.Site.Replace(Chr(34), "")
                    My.Computer.FileSystem.WriteAllText(Form1.baseDir & "\FILES\DATABASE\Threat\" & Microsoft.VisualBasic.Left(link.Text, 2) & ".txt", vbNewLine & linkText & linkSite, True)
                ProgBar.Value = ProgBar.Value + 1

        End If
        ProgBar.Value = 0
    End Sub
When the code is executed it returns the following exception:
System.InvalidOperationException was unhandled by user code
Message="An error occurred creating the form. See Exception.InnerException for details. The error is: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it."

At the line that says My.Computer.FileSystem.WriteAllText(Form1.baseDir & "\FILES\DATABASE\Threat\" & l & m & ".txt", "DATABASE:THREATS", False) in BackgroundWorker_DoWork.

What should I do to stop this exception?
SidT is offline  

My Computer Forum is free to register and we welcome everyone!

July 19th, 2009, 09:48 PM   #2
Joined: Dec 2007
Posts: 187
Re: Visual Basic InvalidOperationException

lol man I wish I could program, but it's a long way for me to go to master programming stuff
johnny is offline  

  My Computer Forum > Computer Science Forum > Programming

basic, invalidoperationexception, visual

Search tags for this page
Click on a term to search for related topics.
Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
some basic question mhhjt Artificial Intelligence 0 November 1st, 2013 01:01 PM
Visual Basic 6 Question KingATG Programming 2 December 9th, 2011 01:43 AM
Building a basic calculatror stuart Programming 1 June 9th, 2010 09:49 PM
Visual Studio -- text boxes CRGreathouse Programming 3 December 9th, 2008 12:50 AM
What are basic and dynamic disks? tangyan Computer Science 0 December 31st, 1969 04:00 PM

Copyright © 2019 My Computer Forum Forum. All rights reserved.