Dear Friends,

usually when we made a method.
ex :

   private void  test (bool vBoll, int vInt)
   {
   }

and when we call that method.we will use like this :
ex:

test( True,3 )

but I have a method like this
ex:

private static void EventFire( Delegate raisedEvent, params object[] args )

so when I call that method what value i use for raiseEvent?(since I don't know what is Delegate)
please help me....

Thanks,

Ive not seen one like the one you show, however..

For example:

delegate void SetTextCallback(String text);

        private void settext(String newtext)
        {
            if (this.textBox2.InvokeRequired)
            {
                SetTextCallback d = new SetTextCallback(settext);
                this.Invoke(d, new object[] { newtext });
            }
            else
            {
                try
                {

                    this.textBox2.AppendText(newtext);
                    this.textBox2.Update();
                }
                catch (System.Exception excpt)
                {//
                }                
            }
        }

which uses delegates to work with threads..

I think what you're methods asking for there is for

EventFire( new delegate(your_event_handler),new object[] { params,go,here });

@^ thanks

but I have another problem
this is my code:

public static class B
{
 public static void A( Delegate raisedEvent, params object[] args )
        {
            // skip if no event
            if( raisedEvent == null )
            {
                return;
            }

            // scroll thru each event and push
            foreach( Delegate sink in raisedEvent.GetInvocationList() )
            {
                try
                {
                    sink.DynamicInvoke( args );
                }
                catch( TargetInvocationException e )
                {
                    Console.Writeline("a");
                }
                catch( TargetException e )
                {
                    Console.Writeline("b");
                }
                catch( MemberAccessException e )
                {
                    Console.Writeline("c");
                }
            }
        }
}

and to test that void I use this test code:

public class C
{
         private static int? MyFunc( int? tes1 )
        {
            throw new Exception( "error" );
        }

        private event SimpleDelegate simpleDelegate = new SimpleDelegate( MyFunc );

        [TestMethod()]
        public void EventFireTest()
        {
             B tes = new B();
             tes.A( simpleDelegate , 3 );          
        }
}

and my test code will give me the TargetInvocationException that I expected.

My question is:

how I can get a TargetException and MemberAccessException ?
what code should I use to get that exception?

Please help me...
Thanks,

how do you mean "get"? do you mean how do you detect that error and handle it?

Look at try and catch which you had before.

I mean is..
Can my code handle TargetException and MemberAccessException ?
it's true that i use try and catch to handle an exception.

for example:
-------------------------------------
public class C
{
private static int? MyFunc( int? tes1 )
{
throw new Exception( "error" );
}
-----------------------------------------
is used to test TargetInvocationException.


but I have to prove 2 other exception are handle by my code, so I must debug my code.
but I never have any case to prove it.

can u give me a case about that exception?

In your catch area, test which kind of error was thrown, and then do something accordingly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.