02-28-2012 11:44 AM
Hi!
I' m trying to get Threading to work in my Plugin.
Sub BtnCalcContactDataClick(sender As Object, e As EventArgs) If z.CalcOK = True Then z.CalcOK = False ' Trying to stop multiple Threads dim strATA as Thread strATA = New Thread(AddressOf Me.CalcCurrentContact) strATA.SetApartmentState(threading.ApartmentState.STA) Try strATA.Start() Catch ex As Exception msgbox(ex.Message) End Try End If End Sub
This Thread runs CalcCurrentContact() just great.
The problem comes when I'm trying to run this Thread while opening a Form in my Plugin:
Sub LblPRNClick(sender As Object, e As EventArgs) If z.CalcOK = True Then z.CalcOK = False dim strATA as Thread strATA = New Thread(AddressOf Me.CalcCurrentContact) strATA.SetApartmentState(threading.ApartmentState.STA) try strATA.Start() Catch ex As Exception msgbox(ex.Message) End Try End If Dim ActToPRN As New ActToPRN() z.ActToPRNopen = 1 ' the Form is now open ActToPRN.ShowDialog() End Sub
The Thread tends to get cut off during program execution, when the Form opens.
Any ideas/recommendations on this Code, and/or recommendations on how to use Threads in an ACT! Plugin?
Thanks!
02-28-2012 01:36 PM
I've found out the issue.
The Thread, and the Form called, CANNOT have any TextBox updates, or the Plugin will crash.
In the Form, the following in the OnLOAD() event will/can cause the Plugin to crash:
Public Sub OnLoad() ' The Me.InitializeComponent call is required for Windows Forms designer support. Me.InitializeComponent() z.ActToPDFopen = 1 txtPDFforms.Text = z.PDFforms ' this line stops the Plugin FillFileGrid() FillListBox() End Sub
Commenting out the TextBox instruction allows the Plugin to work:
Public Sub OnLoad() ' The Me.InitializeComponent call is required for Windows Forms designer support. Me.InitializeComponent() z.ActToPDFopen = 1 ' txtPDFforms.Text = z.PDFforms ' This works! FillFileGrid() FillListBox() End Sub
Go figure...
02-28-2012 01:36 PM
I've found out the issue.
The Thread, and the Form called, CANNOT have any TextBox updates, or the Plugin will crash.
In the Form, the following in the OnLOAD() event will/can cause the Plugin to crash:
Public Sub OnLoad() ' The Me.InitializeComponent call is required for Windows Forms designer support. Me.InitializeComponent() z.ActToPDFopen = 1 txtPDFforms.Text = z.PDFforms ' this line stops the Plugin FillFileGrid() FillListBox() End Sub
Commenting out the TextBox instruction allows the Plugin to work:
Public Sub OnLoad() ' The Me.InitializeComponent call is required for Windows Forms designer support. Me.InitializeComponent() z.ActToPDFopen = 1 ' txtPDFforms.Text = z.PDFforms ' This works! FillFileGrid() FillListBox() End Sub
Go figure...