Click here to Skip to main content
15,908,673 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionHow to Update and Retrieve records on server? Pin
NeilRanjan29-Jul-09 19:53
NeilRanjan29-Jul-09 19:53 
AnswerRe: How to Update and Retrieve records on server? Pin
Pete O'Hanlon29-Jul-09 21:38
mvePete O'Hanlon29-Jul-09 21:38 
QuestionSort grouped listview in Windows XP Pin
JarpoK29-Jul-09 1:33
JarpoK29-Jul-09 1:33 
QuestionLogging and Instrumentation Pin
Sandumone28-Jul-09 10:32
Sandumone28-Jul-09 10:32 
AnswerRe: Logging and Instrumentation Pin
Mike Ellison28-Jul-09 10:57
Mike Ellison28-Jul-09 10:57 
AnswerRe: Logging and Instrumentation Pin
martin_hughes28-Jul-09 10:59
martin_hughes28-Jul-09 10:59 
AnswerRe: Logging and Instrumentation Pin
Mike Ellison28-Jul-09 11:00
Mike Ellison28-Jul-09 11:00 
QuestionUpgrading a VB.net Windows application from Visual Studio 2003 to VS 2005 Pin
BryanMac78928-Jul-09 0:57
BryanMac78928-Jul-09 0:57 
I wonder if anyone can help.

I am upgrading a Windows Application from Visual Studio 2003 to 2005. After running the conversion wizard and changing/rewriting several methods I got the app to compile (already works perfectly in VS 2003)

However when running the project with a Debugger attached in 2005 and I select the open file dialog box which executes the below code I get the error "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. This exception is only raised if a debugger is attached to the process.".

The stack trace is shown as

at System.Windows.Forms.FileDialog.RunDialog(IntPtr hWndOwner)
at System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
at System.Windows.Forms.CommonDialog.ShowDialog()
at Pupil_Accounts_Final_App.frmmain.importbob() in C:\Documents and Settings\*****\My Documents\Visual Studio 2005\*****Accounts App V2 database upgrade\frmmain.vb:line 379
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


So I then went into my puplicMain class which invokes the form (frmmain) where the button is located for calling the code to start the threaded process to call the method to open the dialog and added the SingleThreadAttribute as shown in the main code below, however the same error is still thrown. I then added this attribute to the button click event and the method (again shown below) but again same problem again.

I have been searching about the Web for several hours trying to find a solution however found one similar article which suggested removing all old DLL files in the BIN directory, I tried this still no luck. Does anyone have any idea what my problem could be? MSDN and all my other usual methods of debugging are just not working with this...


Method for open dialog:

STAThreadAttribute() _
    Private Sub importpupils_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnimportbob.Click
        'starts threading to make program appear faster and optomise performance
        Dim t As New Thread(AddressOf importbob)
        t.Name = "Import Bob"
        importPupilsThread = True
        t.Start()
    End Sub

    <STAThreadAttribute()> _
    Public Sub importbob()
        'this sub open's a stream reader so bob's master file can be taken into the program
        Dim file As FileStream
        Dim inputstream As StreamReader
        Dim temp As String
        Dim item As ListViewItem
        Dim i As Integer

        open.Filter = "CSV File (*.csv)|*.csv"
        If open.ShowDialog = DialogResult.OK Then
            Try
                file = New FileStream(open.FileName, FileMode.Open)
                inputstream = New StreamReader(file)
            Catch ex As Exception
                MsgBox("A Exception has occured." + vbCrLf + ex.Message)
                Exit Sub
            End Try
            btnimportbob.Enabled = False

            Try
                Do While inputstream.Peek > -1
                    temp = inputstream.ReadLine
                    item = bobslist.Items.Add(temp.Split(",", 11, StringSplitOptions.None)(0))
                    For i = 1 To 10
                        item.SubItems.Add(temp.Split(",", 11, StringSplitOptions.None)(i).Trim)
                    Next
                Loop
            Catch ex As Exception
                MsgBox("A exception has occured. You may have imported the wrong file or the file is corupt" + vbCrLf + ex.Message)
                inputstream.Close()
                importPupilsThread = False
                Exit Sub

            End Try
            inputstream.Close()
        End If

        importPupilsThread = False
        btnimportseemis.Enabled = True
    End Sub


Main entry point to the program publicMain

Module publicmain
    Public Const appversion As String = "2.0.0"
    Public Const appauthor As String = "*****"
    Public Const apptitle As String = "*******"
    Public MainForm As frmmain
    Public importPupilsThread As Boolean = False
    Public importSeemisThread As Boolean = False
    Public nextThread As Boolean = False


    ' Main entry point in to application
    ' Creates new instance of the main form then shows the dialog
    <STAThreadAttribute()> _
    Sub Main()
        MainForm = New frmmain()
        MainForm.ShowDialog()
    End Sub

AnswerRe: Upgrading a VB.net Windows application from Visual Studio 2003 to VS 2005 Pin
Luc Pattyn28-Jul-09 2:12
sitebuilderLuc Pattyn28-Jul-09 2:12 
GeneralRe: Upgrading a VB.net Windows application from Visual Studio 2003 to VS 2005 Pin
BryanMac78928-Jul-09 3:14
BryanMac78928-Jul-09 3:14 
Questionhello ,,,, i need help ,,,, please about MCTS 70-536 Microsoft PressBook Pin
H.Hemdan27-Jul-09 7:55
H.Hemdan27-Jul-09 7:55 
AnswerRe: hello ,,,, i need help ,,,, please about MCTS 70-536 Microsoft PressBook Pin
Abhijit Jana27-Jul-09 8:36
professionalAbhijit Jana27-Jul-09 8:36 
QuestionStrange Regasm related upgrade issue Pin
Russell Jones27-Jul-09 2:34
Russell Jones27-Jul-09 2:34 
AnswerRe: Strange Regasm related upgrade issue Pin
Dave Kreskowiak27-Jul-09 4:45
mveDave Kreskowiak27-Jul-09 4:45 
GeneralRe: Strange Regasm related upgrade issue Pin
Russell Jones27-Jul-09 4:56
Russell Jones27-Jul-09 4:56 
Questionsplit Container scroll bars Pin
Surya Ayyagari27-Jul-09 0:43
Surya Ayyagari27-Jul-09 0:43 
AnswerRe: split Container scroll bars Pin
Henry Minute27-Jul-09 1:45
Henry Minute27-Jul-09 1:45 
GeneralRe: split Container scroll bars Pin
Surya Ayyagari27-Jul-09 1:59
Surya Ayyagari27-Jul-09 1:59 
GeneralRe: split Container scroll bars Pin
Henry Minute27-Jul-09 2:09
Henry Minute27-Jul-09 2:09 
Questionwindow media with Remote control Pin
heinhtetoo26-Jul-09 23:48
heinhtetoo26-Jul-09 23:48 
QuestionClient Side Javascript Enabled Check Pin
Tristan Rhodes26-Jul-09 23:42
Tristan Rhodes26-Jul-09 23:42 
QuestionHow to Retrieve TCP/UDP Statistics using System.Net.NetworkInformation Pin
that_dude_tj26-Jul-09 23:06
that_dude_tj26-Jul-09 23:06 
AnswerCP Ignore - Crossposted in multiple forums... Pin
Dave Kreskowiak27-Jul-09 4:47
mveDave Kreskowiak27-Jul-09 4:47 
Questionhow to hide properties in propertyGrid Pin
Hamid Amrbdi26-Jul-09 21:43
Hamid Amrbdi26-Jul-09 21:43 
AnswerRe: how to hide properties in propertyGrid Pin
DaveyM6927-Jul-09 0:35
professionalDaveyM6927-Jul-09 0:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.