473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Handeling exceptions when using threads

I have a main form (frmMain).
frmMain creates a sub form (frmSub).
frmSub creates a business object (busObj).
busObj creates a thread and calls a method to run in the thread.
The method creates a server side buiness object (busObjSrv).
busObjSrv creates an Excel.Application (exAp) object on the server.
exAp opens an automated excel woekbook (exWb) (automated by an outside
company)
busObjSrv fills the information from frmSub on exWb and calls the automation
methods.
The automation methods generate 2 word documents based on the information
from frmSub, and data from the other company located on the work book.

Sorry for the long explenation, but heres the problem...

once busObj spins the thread off, frmSub closes and breaks the object link
between busObj and frmMain. If an exception is thrown in busObjSrv, I cannot
pass it back to frmMain to display to the user through the catch blocks. A
general exception gets thrown (break/continue) and the program does not blow
up, but the exception is not being handled properly (IMO).

Does anyone know a way that I can pass the exception back to frmMain to
display in a MessageBox?

We have several business objects that use threading, and I would like to
incorporate a solution into a utility object that we can use for all
threading.

If I figure it out first... I will post the solution in case someone else
needs it.

Thanks in advance.

bobc
Nov 16 '05 #1
5 1557
How about an event that is fired when a exception gets thrown. You can
then have an exception handler that subscribes to the events and
displays something in the UI when the event gets fired.

Nov 16 '05 #2
If the sub form creates the business object and then goes away, how does the
main form know that the business object even exists?

bobc

"Bob Calvanese" <bc********@comcast.net> wrote in message
news:z4********************@comcast.com...
I have a main form (frmMain).
frmMain creates a sub form (frmSub).
frmSub creates a business object (busObj).
busObj creates a thread and calls a method to run in the thread.
The method creates a server side buiness object (busObjSrv).
busObjSrv creates an Excel.Application (exAp) object on the server.
exAp opens an automated excel woekbook (exWb) (automated by an outside
company)
busObjSrv fills the information from frmSub on exWb and calls the
automation methods.
The automation methods generate 2 word documents based on the information
from frmSub, and data from the other company located on the work book.

Sorry for the long explenation, but heres the problem...

once busObj spins the thread off, frmSub closes and breaks the object link
between busObj and frmMain. If an exception is thrown in busObjSrv, I
cannot pass it back to frmMain to display to the user through the catch
blocks. A general exception gets thrown (break/continue) and the program
does not blow up, but the exception is not being handled properly (IMO).

Does anyone know a way that I can pass the exception back to frmMain to
display in a MessageBox?

We have several business objects that use threading, and I would like to
incorporate a solution into a utility object that we can use for all
threading.

If I figure it out first... I will post the solution in case someone else
needs it.

Thanks in advance.

bobc

Nov 16 '05 #3
Well, you have to make the MainForm subscribe to events fired from the
business object.

Regards
Senthil

Nov 16 '05 #4
So even though the main form creates the sub form, and the sub form creates
the business object, and the sub form closes... That the main form knows
that there is a business object?

I thought that the business object would only be known by the object that
created it. Could you explain how that is form me so I can understand?

I'll give it a try... Thanks
bobc
"sadhu" <se**********@wdevs.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Well, you have to make the MainForm subscribe to events fired from the
business object.

Regards
Senthil

Nov 16 '05 #5
Something like this

public class MainForm : Form
{
public void CreateSubForm()
{
SubForm s = new SubForm(this);
s.Show();
}

internal void ExceptionHandler(Exception e)
{
MessageBox.Show(e.ToString());
}
}

class SubForm : Form
{
MainForm f;
public SubForm(MainForm f)
{
this.f = f;
}
void CreateBusinessObject()
{
BusinessObject bo = new BusinessObject();
bo.ExceptionOccurred += new
ExceptionOccurredEventHandler(f.ExceptionHandler);
}
}

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
by: Steven Bethard | last post by:
I feel like this has probably been answered before, but I couldn't find something quite like it in the archives. Feel free to point me somewhere if you know where this has already been answered. ...
26
by: OvErboRed | last post by:
I just read a whole bunch of threads on microsoft.public.dotnet.* regarding checked exceptions (the longest-running of which seems to be <cJQQ9.4419 $j94.834878@news02.tsnz.net>. My personal...
8
by: Shane Groff | last post by:
I know this is a recurring discussion (I've spent the last 3 days reading through threads on the topic), but I feel compelled to start it up again. After reading through the existing threads, I...
6
by: RepStat | last post by:
I've read that it is best not to use exceptions willy-nilly for stupid purposes as they can be a major performance hit if they are thrown. But is it a performance hit to use a try..catch..finally...
5
by: Miyra | last post by:
Hi. I'm working with an app that uses exceptions for control flow. These are code blocks where exceptions are thrown/caught regularly. A couple hundred exceptions occur per hour and they're caught...
16
by: Einar Høst | last post by:
Hi, I'm getting into the Trace-functionality in .NET, using it to provide some much-needed logging across dlls in the project we're working on. However, being a newbie, I'm wondering if some...
10
by: Cool Guy | last post by:
Consider: void Start() { if (!TryToDoSomething()) ShowErrorMessage(); }
6
by: robert | last post by:
I get python crashes and (in better cases) strange Python exceptions when (in most cases) importing and using cookielib lazy on demand in a thread. It is mainly with cookielib, but remember the...
25
by: Denis Kukharev | last post by:
I have a problem when catching a plenty of exceptions simultaneously in different threads: the Load Average indicator exceeds 100.0 and the process seems to "hang up". I managed to simulate this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.