المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Global ( sort of) event ?



C# Programming
05-08-2009, 01:41 PM
Hi,

I have a class library, which actuall is a little application itself. It does communication with our server, starts a download queue and autodownloader and does some background processing.


This to provide data and files for the different host app's that are using this class library ( see it as a communications client)

now in the library, i have some events that need to be received by the host app like for example:

FileCountChanged. the problems is, this can be triggered from The AutoDownloader because it finished a download, from the TCP Client cause the server told him to delete a file etc etc..

Now my question is: is there a way to raise a global event from different classes ?

The more or less same question applies to variables ( objects). Can i change the variable of my main class from its sub classes ?

Something like for example:








public delegate void FileCountChangedEventHandler(FileType filetype,int count);
public class MyClient
{

// Should be raised if:
// File get's deleted, File is added,
// This can be initiated from many different classes...
// How do
public event FilecountChanged(FileType filetype,int count);
private DownloadQueue _dlqueue = new _dlqueue();

// I should be able to add and remove downloads in this queue from anywhere HOWEVER.. it must be this queue. Do i have to pass this to
// all the classes that need to use it ? And do i use ref or just normal ?
private AutoDownloader dl = null;
public Myclient()
{
dl = new AutoDownloader(_dlqueue);
dl.start();
dl.DownloadCompleted += new eventhandler(ondownloadcompleted);
}



}



Thanks !

Do Or Don't, there is no "try catch ex as exception end try"