Hey Tom,
Thanks for the Reply.
Here is what is some code:
This runs on a menu click handler:
Dim objReports As Reports
objReports = New ExcelPayrollCD( strFullFileName ,
g_objTables.Con nection, intSerial)
AddHandler objReports.Repo rtFinished, AddressOf
objReports_Repo rtFinished
Dim objNewThreadSta rt As New Threading.Threa dStart(AddressO f
objReports.Gene rate)
Dim objNewThread As New Threading.Threa d(objNewThreadS tart)
objNewThread.St art()
And there is this sub to handle the above code:
Private Sub objReports_Repo rtFinished(ByVa l sender As Excel.Reports)
Dim Result As Excel.ReportRes ults
Result = sender.ReportRe sult
Dim objNewThreadSta rt As New Threading.Threa dStart(AddressO f
CType(sender, IDisposable).Di spose)
Dim objNewThread As New Threading.Threa d(objNewThreadS tart)
objNewThread.St art()
Select Case Result
Case Excel.ReportRes ults.OK
MessageBox.Show ("Report created!" & vbNewLine &
sender.FullFile Name & " saved.", "Payroll CD", MessageBoxButto ns.OK,
MessageBoxIcon. Information, MessageBoxDefau ltButton.Button 1)
Case Excel.ReportRes ults.Cancelled
MessageBox.Show ("Report cancelled.")
Case Excel.ReportRes ults.Connection TimeOut
MessageBox.Show ("Connection Timed Out.")
Case Excel.ReportRes ults.DataNotRet rived
MessageBox.Show ("Data Not Retrived.")
Case Excel.ReportRes ults.ReportMode lNotFound
MessageBox.Show ("Report model not found.")
Case Excel.ReportRes ults.UnknownErr or
MessageBox.Show ("Unkown Error.")
Case Else
End Select
End Sub
I want to catch an error on objReports.Gene rate, which is run at
objNewThread.St art.
Normally, without MultiThreading, I'd simply do:
Try
objReports.Gene rate()
Catch
'do whatever
Finally
objReports.Disp ose
End Try
but I can't because there is no direct call to objReports.Gene rate, and
objReports.Disp ose only runs when Sub objReports_Repo rtFinished gets called.
Any ideas?
Thanks again!
Giovanni Bassi
"Tom Shelton" <to*@mtogden.co m> wrote in message
news:ue******** *****@TK2MSFTNG P11.phx.gbl...
On 2003-10-15, Giovanni Bassi <gb****@coair.c om> wrote: Hello Group,
I am running an operation in a different thread. There are resources
that are released when the thread is done running. This is done at the end of
the execution as it raises an event, and then the operation handling this
event calls threaded object's dispose method.
The problem is: If an exception is thrown the event is never raised, the
operation never executes dispose and my resources get stuck on the
memory until the app is finally closed and then, just then, the finalize method
will call the dispose method.
How can I know if an exception was thrown in a different thread? I need
that to be able to call the dispose method myself and not wait until finalize
runs whenever it feels like.
Thanks in advance for all the replies,
Giovanni Bassi
I think you may want to check into Try-Catch-Finally... The finally
block is always executed - even if an exception is thrown. I'm not
exactly sure with out seeing some code of course, but I would guess this
is a code structure issue. Is there any way you can post a scaled down
snippet of code that illustrates what you are trying to accomplish?
--
Tom Shelton
MVP [Visual Basic]