sending messages from a dll to the main app

G

Guest

Hi,

I have an application that contains a class library as another project.
The application basically executes DTS packages on a remote SQL Server.

This works great.

However I want to add some code that will allow the class executing the
current DTS package to send back messages to the main form of the application.

I have tried using throw new system.exception ("message") this only works
when an exception has occured.

The DTS code I use was taken from the net and has on progress, on error, on
start, on finish events that do a console.writeline.
Instead I would like the message not to go to the console but sent out to a
form label in the application.

I don't want to have to necessarily call an exception as this will cause me
to drop out of the code which is in fact working perfectly fine.

thank you,

Chris
 
J

John Saunders

Chris said:
Hi,

I have an application that contains a class library as another project.
The application basically executes DTS packages on a remote SQL Server.

This works great.

However I want to add some code that will allow the class executing the
current DTS package to send back messages to the main form of the
application.

I have tried using throw new system.exception ("message") this only works
when an exception has occured.

The DTS code I use was taken from the net and has on progress, on error,
on
start, on finish events that do a console.writeline.
Instead I would like the message not to go to the console but sent out to
a
form label in the application.

First, you'll probably get more help with this by asking in one of the SQL
Server newsgroups, perhaps microsoft.public.sqlserver.programming or .dts.

You'll have to go look at the API used to execute the remote DTS package to
see if it has any way to pass events back. If it does, then perhaps you
could pick up those events in the .NET class which calls that API. That
class could raise an event when it receives one from the DTS package. The
form could listen for that event and update its label.

John Saunders
 
G

Guest

Hi Chris,

Exceptions must never be (mis)used to control normal program behaviour -
they are only ever meant to be used for the management of unexpected errors.
The good news is that there is a feature in .NET for solving exactly your
type of problem - delegates/events.

If I understand you right, the following is true of your app - the GUI uses
DTSCode which then uses/calls RemoteSQLServer (excuse my naming).

What you might want to do is create a public event in DTSCode, and when
constructing DTSCode objects from the GUI, 'tell' the DTSCode event that the
GUI 'is interested' to know when the public event in the DTSCode occurs.
Events also allow the passing of information, so your command line messages
can be sent from the DTSCode to the GUI, which in turn can display the
messages on the GUI screen.

If on the other hand you don't have direct access to DTSCode sources, you
could write your own DTSCode wrapper class that wraps the DTSCode
functionality, but which also declares/generates the event when/where
required. In this case your GUI will declare an interest in the public event
of the DTS code wrapper.

Have a look at the following link(s) for examples of this
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkEventsTutorial.asp
http://www.codeproject.com/csharp/delegates-part1.asp

HTH,
Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top