|
Please don't use bold for the whole post.
|
|
|
|
|
We talk about C# in this forum. If it happens to work under Mono, that's fine, be we don't talk specifically about it because, well, this is a Windows programming site.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I've used Mono and am familiar with it, but this is a question/answer forum.
Mono is a follower, not a leader. So if you're going to dedicate your time I would suggest .Net and then incorporate that into what you'd like to learn about Mono later.
|
|
|
|
|
I want to use the event of other class in my main clas help me out.
public class ParenctClass
{
public delegate void myDel(string data); .
public event myDel MYEVENT;
public void Some Fucntion
{
// Thourgh function i put some data in "data"
}
}// end Parenct Class
public class MainClass
{
// here how can i access "MYEVENT" event
}
thaks in advance for reply
|
|
|
|
|
Is MainClass derived from ParentClass ? Your event is raised by your class. You can override the method that does this, and/or subscribe to whatever event gets fired to do this. You can also hook up the derived class to recieve the event.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
No sir the MainClass in not overrided from Parent class.
I got your idea but the probem is that MainClass is i overrideing from "Form" class
No the condition is same i have to call the ParenctCass(parent in sence i have to call my Custom Event) and use my ovent event.
|
|
|
|
|
Declare the event static in your parent class and then subscribe to that event from the main class
public class Parent
{
public delegate void MyDelegate(string str);
public static event MyDelegate MYEvent;
public void Myunc()
{
if (MYEvent != null)
{
MYEvent("hello listeners");
}
}
}
<pre>
public class MainClass
{
public MainClass()
{
//subscribe to the event from Parent Class
Parent.MYEvent += new Parent.MyDelegate(Parent_MYEvent);
}
// called when event is triggered
public void Parent_MYEvent(object sender, EventArgs e)
{
}
}
|
|
|
|
|
good answer but your event handler doesnt match the delegate:
public void Parent_MYEvent(object sender, EventArgs e)<br />
{ <br />
<br />
}
should be
public void Parent_MYEvent(string info)<br />
{ <br />
<br />
}
|
|
|
|
|
Indeed, I wrote the answer with an Eventhandler delegate and after I noticed he needs a custom delegate I changed the code, but forgot to change the method parameters
modified on Monday, April 28, 2008 4:56 AM
|
|
|
|
|
thanks for replying you got 5
|
|
|
|
|
Your technique is ok when i am using function in Parenct class but if i am useing event in Parent then it fail.
i write the code which belew
<br />
<br />
public class Parent : TreeView<br />
{<br />
public delegate void MyDelegate(string str);<br />
public static event MyDelegate MYEvent;<br />
<br />
protected override void OnBeforeExpand(TreeViewCancelEventArgse)<br />
{<br />
if (MYEvent != null)
{<br />
Parent.MYEvent("hello listeners");
}<br />
}<br />
}<br />
<br />
<br />
public class MainClass<br />
{<br />
public MainClass()<br />
{<br />
Parent.MYEvent += new Parent.MyDelegate(Parent_MYEvent);<br />
}<br />
<br />
public void Parent_MYEvent(string str)<br />
{ <br />
MessageBox(str);<br />
}<br />
}<br />
<br />
|
|
|
|
|
MyEvent is not going to be null if somebody subscribed to this event, like you are doing in the main class
public MainClass()
{
Parent.MYEvent += new Parent.MyDelegate(Parent_MYEvent);
}
that means if your OnBeforeExpand function will be hit before you subscribe to the MyEvent in the main class, this event will be always null.
|
|
|
|
|
Hi All:
I need to capture Http GET/POST data sent from one page to another in IE using C#.
Can someone please help me out...
|
|
|
|
|
Hi,
In our web application (ASP.NET and C# is used) some temporary dll files are created with random names (includes some letter and numbers). Is this a property of .NET framework?
Do anyone have information about this situation.
Thanks for your help.
|
|
|
|
|
yes. Why is it a problem ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
Hello everyone,
Two simple questions about C# threadpool.
1. C# CLR only has one thread pool per process, means the asynchronous method call (implicit using thread pool) and the explicit using thread pool by ThreadPool.QueueUserWorkItem will share the same thread pool?
2. For the exceptions occured in asynchronous method call, when we call EndInvoke, if exception is thrown and we can catch the exception. But when we use the the thread pool explicitly by ThreadPool.QueueUserWorkItem, we can not catch any exception occured?
thanks in advance,
George
|
|
|
|
|
These are not simple questions
1. using directly the ThreadPool by QueueUserWorkItem or indirectly by asynchronous methods will share the same thread pool.
2. In .NET 2.0 any unhandled exception on any thread shuts down the application (see here[^])
The solution is to
- use a try/catch block in every thread entry method (in order to avoid application shutdown in case of an unhandled exception)
- or use the application domain AppDomain.UnhandledException event.
|
|
|
|
|
Thanks Zoltan,
I have read the link, looks cool! One simple question, what means "The common language runtime or a host process terminates the thread by throwing an internal exception." Could you show me a sample please?
regards,
George
|
|
|
|
|
It means that if the thread method does not contain a try/catch block the application will be terminated.
Example (try it with/without the try/catch)
public static void Main()
{
new Thread(TestMethod).Start();
}
static void TestMethod()
{
int i=0;
double result;
try { result = 100/i; }
catch (DivideByZeroException exc)
{ Console.Write(exc.Message); }
}
|
|
|
|
|
Thanks Zoltan!
What means "internal exception"? Which exception in your sample is internal exception? (Is internal exception something that is CLR internal used exception type, which is not exposed?)
regards,
George
|
|
|
|
|
The DivideByZero is the internal exception. I guess the term internal means in this context that the exception will be one of the type derived from System.Exception.
|
|
|
|
|
Thanks Zoltan,
I read the documents you referred before again, there is a statement "provides a backstop for certain unhandled exceptions", backstop means?
regards,
George
|
|
|
|
|
google it![^]
You don't need to understand each word in a documentation. Try to understand the principles and the rest will follow in time.
|
|
|
|
|
Thanks Zoltan,
I understand what is the meaning of backstop in English. But I do not understand what means "provides a backstop for certain unhandled exceptions" in the context. Does it mean for the scenarios listed in the MSDN page, CLR will prevent process will termination by a backstop? I do not think so, I have tested uncaught exception will cause process terminated. So, what makes me confused is what means "provides a backstop for certain unhandled exceptions".
Any ideas?
--------------------
- A ThreadAbortException is thrown in a thread because Abort was called.
- An AppDomainUnloadedException is thrown in a thread because the application domain in which the thread is executing is being unloaded.
- The common language runtime or a host process terminates the thread by throwing an internal exception.
--------------------
regards,
George
|
|
|
|