I'm trying to create a pretty easy threaded application but I keep getting an error message:
Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.
I am aware that I should only alter the properties of a control from the thread in which it was created on, but I'm not altering the control directly from another thread. This is my current source:
VB Code:
Imports System.IO Imports System.Threading Public Class MainForm Private WithEvents _pdfMaker As PDFMaker Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click If (browseDialog.ShowDialog = Windows.Forms.DialogResult.OK) Then txtArchiveFilePath.Text = browseDialog.FileName End If End Sub Private Sub btnBurnFiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBurnFiles.Click _pdfMaker = New PDFMaker Dim mainThread As Thread = New Thread(AddressOf _pdfMaker.createPdfFromTiffArchive) _pdfMaker.ArchivePath = txtArchiveFilePath.Text _pdfMaker.TempDir = "C:\test\" mainThread.Start() End Sub Private Sub _pdfMaker_TiffAdded(ByVal percentDone As Double) Handles _pdfMaker.TiffAdded currentProgress.Value = percentDone txtStatus.Text = "Building PDF File (" & percentDone & "%)" End Sub End Class
The error message is coming from currentProgress.Value = percentDone. currentProgress is an object of type toolStripProgressBar. For some reason though if i comment that line out the next line: txtStatus.Text = "Building PDF File (" & percentDone & "%)" does not trigger an error... any ideas?




Reply With Quote