Community
Showing results for 
Search instead for 
Do you mean 
Reply

Using Threads in a Plugin

Accepted Solution Solved
Copper Super Contributor
Posts: 88
Country: USA
Accepted Solution

Using Threads in a Plugin

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!


Accepted Solutions
Solution
Accepted by topic author kimkamp22
‎09-25-2015 03:20 AM
Copper Super Contributor
Posts: 88
Country: USA

Re: Using Threads in a Plugin

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...

View solution in original post


All Replies
Solution
Accepted by topic author kimkamp22
‎09-25-2015 03:20 AM
Copper Super Contributor
Posts: 88
Country: USA

Re: Using Threads in a Plugin

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...