Click here to Skip to main content
15,901,426 members
Home / Discussions / C#
   

C#

 
GeneralRe: Sending email Pin
kpuneeth711-Mar-10 18:39
kpuneeth711-Mar-10 18:39 
AnswerRe: Sending email Pin
Rod Kemp11-Mar-10 20:13
Rod Kemp11-Mar-10 20:13 
GeneralRe: Sending email Pin
kpuneeth711-Mar-10 20:21
kpuneeth711-Mar-10 20:21 
GeneralRe: Sending email Pin
Rod Kemp11-Mar-10 20:43
Rod Kemp11-Mar-10 20:43 
GeneralRe: Sending email Pin
kpuneeth711-Mar-10 20:46
kpuneeth711-Mar-10 20:46 
Questionhow to open excel file for edit and save back into the same file. Pin
neodeaths11-Mar-10 15:52
neodeaths11-Mar-10 15:52 
AnswerRe: how to open excel file for edit and save back into the same file. Pin
Luc Pattyn11-Mar-10 16:42
sitebuilderLuc Pattyn11-Mar-10 16:42 
AnswerRe: how to open excel file for edit and save back into the same file. Pin
dybs13-Mar-10 16:32
dybs13-Mar-10 16:32 
Questionencoding/decoding, still cant figure it out? Pin
stephen.darling11-Mar-10 14:51
stephen.darling11-Mar-10 14:51 
AnswerRe: encoding/decoding, still cant figure it out? Pin
Dr.Walt Fair, PE11-Mar-10 16:00
professionalDr.Walt Fair, PE11-Mar-10 16:00 
GeneralRe: encoding/decoding, still cant figure it out? Pin
Rod Kemp11-Mar-10 16:08
Rod Kemp11-Mar-10 16:08 
AnswerRe: encoding/decoding, still cant figure it out? [modified] Pin
Rod Kemp11-Mar-10 16:03
Rod Kemp11-Mar-10 16:03 
AnswerRe: encoding/decoding, still cant figure it out? [modified] Pin
#realJSOP12-Mar-10 1:55
professional#realJSOP12-Mar-10 1:55 
GeneralRe: encoding/decoding, still cant figure it out? Pin
Rod Kemp12-Mar-10 3:48
Rod Kemp12-Mar-10 3:48 
Questionhow can i enable back newToolStripMenuItem to true Pin
crisjala11-Mar-10 14:03
crisjala11-Mar-10 14:03 
AnswerRe: how can i enable back newToolStripMenuItem to true Pin
DaveyM6911-Mar-10 14:18
professionalDaveyM6911-Mar-10 14:18 
GeneralRe: how can i enable back newToolStripMenuItem to true Pin
crisjala11-Mar-10 19:27
crisjala11-Mar-10 19:27 
GeneralRe: how can i enable back newToolStripMenuItem to true Pin
crisjala11-Mar-10 20:37
crisjala11-Mar-10 20:37 
GeneralRe: how can i enable back newToolStripMenuItem to true Pin
DaveyM6912-Mar-10 3:51
professionalDaveyM6912-Mar-10 3:51 
QuestionCatch Asynchronous Exception? Pin
Matthew Klein11-Mar-10 9:42
Matthew Klein11-Mar-10 9:42 
AnswerRe: Catch Asynchronous Exception? Pin
AspDotNetDev11-Mar-10 13:36
protectorAspDotNetDev11-Mar-10 13:36 
AnswerRe: Catch Asynchronous Exception? Pin
Luc Pattyn11-Mar-10 13:46
sitebuilderLuc Pattyn11-Mar-10 13:46 
GeneralRe: Catch Asynchronous Exception? Pin
Matthew Klein11-Mar-10 14:18
Matthew Klein11-Mar-10 14:18 
GeneralRe: Catch Asynchronous Exception? Pin
Luc Pattyn11-Mar-10 14:33
sitebuilderLuc Pattyn11-Mar-10 14:33 
QuestionRemoting & Events ("Exception has been thrown by the target of an invocation.”) Pin
bluescreen7611-Mar-10 8:41
bluescreen7611-Mar-10 8:41 
Hi,
I have been struggling with receiving events from a server to a client (using .NET remoting) for quite a long time now but I keep receiving the following message on client side (“Exception has been thrown by the target of an invocation.”). This message is received as the server is trying to call the event handler while the event handler exists in the client and since the client assembly is not available on the side of the server, this message comes.
Any idea?

Server Class library
-----------------------------
public delegate void MyDel();
 
    public class ServerClass : MarshalByRefObject
    {
        public event MyDel myEvent;
 
        public void StartServer (bool shouldFireEvent)
        {
            TcpServerChannel tsc;
            BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
            provider.TypeFilterLevel = TypeFilterLevel.Full;
            IDictionary di = new Hashtable();
            di["port"] = 8085;
            di["bindTo"] = "172.19.35.191";
            tsc = new TcpServerChannel(di, provider);
            ChannelServices.RegisterChannel(tsc, false);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(ServerClass), "myURI", WellKnownObjectMode.Singleton);
 
            if (shouldFireEvent)
            {
                while (true)
                {
                    myEvent();
                    Thread.Sleep(1000);
                }
            }
        }
    }



Server GUI
-----------------------------
class ServerGui
    {
        static void Main(string[] args)
        {
            ServerClass server = new ServerClass();
            server.myEvent += new MyDel(ReceivedEventFromServerHandler); //lets register to event
            server.StartServer(true);
            Console.WriteLine("server is running. press enter to quit");
            Console.ReadKey();
        }

        static void ReceivedEventFromServerHandler()
        {
            Console.WriteLine("I am the server GUI. Got a message from the server");
        }
    }


Client
--------------

class ClientClass
    {
        static void Main(string[] args)
        {
            ServerClass server = (ServerClass)Activator.GetObject(typeof(ServerClass), "tcp://172.19.35.191:8085/myURI");
            server.myEvent += new MyDel(server_myEvent); //HERE IT CRASHES
            while (true)
            {
                Thread.Sleep(1000);
            }
        }
 
        static void server_myEvent()
        {
            Console.WriteLine("I am the client. Got a message from the server over the network");
        }
    }

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.