0

I am writing a service based application, and a UI application within it. I am using Event Logs to log my error, but some of these errors are critical and user should be aware of.

What I need is to check if The UI application (Windows Application Project) is available, and running... if it's running send the error directly to the UI through a service based application (Windows Service Project).

Now, what to do? There are two step I should take, first check if UI is running, second send info like a class instance or a string or binary data (like using serialize) to the UI and UI receive it.

robingrindrod
  • 474
  • 4
  • 18
Hassan Faghihi
  • 1,888
  • 1
  • 37
  • 55

2 Answers2

1

I think the two applications of yours can interact using the Socket mechanism.

And check this for the "is running" bit: Checking if my Windows application is running

Community
  • 1
  • 1
Qnan
  • 3,714
  • 18
  • 15
  • i first though about socket, but first it need a port and i dont wanna busy them, because the app will be use over server, and they may need them, second both application are on same machine, and it's better to use windows messaging, if its possible... if no one answer this, i think it will be a good way – Hassan Faghihi Aug 17 '12 at 16:27
  • @deadManN windows messages are not the recommended way to go for C#, check, e.g. the comments to this post (http://social.msdn.microsoft.com/Forums/en/winforms/thread/6a7915f1-42a4-4f82-a2c6-9c149c99d7f1) for details. And I wouldn't worry about using up all the ports, that doesn't happen too often even on servers and you'll only ever need one -- it wont change anything, really. – Qnan Aug 17 '12 at 16:40
  • @deadManN also if you still like to do that with windows messages, try this out: http://ryanfarley.com/blog/archive/2004/05/10/605.aspx – Qnan Aug 17 '12 at 16:49
  • so that wont work with service<--->win app relationship :| ok, but the matter is, how to send serialized info, and know if the port is readed, and then if we should read new data and lot of other things :( – Hassan Faghihi Aug 17 '12 at 17:01
  • i was worked with that previously, but i though they may be a way to send custom msg, but it seem only predefined msg are supported :)) – Hassan Faghihi Aug 17 '12 at 17:05
  • @deadManN might be, you've got to try that out in your particular setup. The point is, however, that the sockets word pretty much anywhere, while the direct messaging may or may not work depending on the way the permissions are set and so on. – Qnan Aug 17 '12 at 17:07
  • 1
    @deadManN by the way, you could also use the Remoting mechanism that log4net is using directly. That allows to pass objects between application, provided they're Serializeable. Lots of info on that here: http://msdn.microsoft.com/en-us/library/kwdt6w2k(v=vs.71).aspx – Qnan Aug 17 '12 at 17:09
  • i find some issue with VS... the i follow the msdn tutorial, and in here: http://msdn.microsoft.com/en-us/library/8019cc4e%28v=vs.71%29 it write a config file, i use visual studio, so i first add app.config, it didnt work, i also changed the name to the same thing as the tutorial say, it again doesnt worked :| what should i do through Visual Studio? – Hassan Faghihi Aug 17 '12 at 18:22
  • so! didn't you know how i should define application config for this job? can't i config it within the application? – Hassan Faghihi Aug 19 '12 at 08:23
  • Nope, that's news to me. But I suggest that you reformulate your question now, assuming the use of this particular mechanism and put it to the community -- I'm sure there're people on SO that have experience with these things and can help you solve the problem. – Qnan Aug 19 '12 at 10:09
  • i did it, but according to the tutorial, the listener dont listen to any thing, so i go read other section... tnx, if i had trouble i call you, please wait for me to take answer, before Mark as answer, otherwise no one will check the post – Hassan Faghihi Aug 19 '12 at 21:41
  • The remoting library was awesome but hard to understand, but i implement it through people articles... – Hassan Faghihi Aug 20 '12 at 13:44
1

If you don't mind adding a new dll to your project I suggest to take a look at log4net. There is an appender for remoting, RemotingAppender that fit perfectly your needing. You just need to find some samples on how to implement the "receiver" in your UI app. As an additional benefit, you can use the same library to append in the EventLog, or on a file and so on.

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
  • i'm not over remote, both application are on same machine, and i'm afraid it need higher process... is this use for local application messaging too? – Hassan Faghihi Aug 17 '12 at 16:25
  • in here, between samples, i see some thing,.. but where to download these sample code? – Hassan Faghihi Aug 17 '12 at 16:37
  • that looks like a good option, thanks for the info, Felice. @deadManN download the sources archive (http://mirror.arcor-online.net/www.apache.org//logging/log4net/source/log4net-1.2.11-src.zip), the examples are in there – Qnan Aug 17 '12 at 16:55
  • Remoting - RemotingServer... where it exactly receive data? i wish to unpack the packet and then create custom error from it :| – Hassan Faghihi Aug 17 '12 at 16:56
  • i did, and ... you see my last msg – Hassan Faghihi Aug 17 '12 at 16:58
  • The sample, do all thing it self... i tried it but my knowledge dont let me do customized thing, all performed with it's console engine... and i have not much time to study whole the document... – Hassan Faghihi Aug 17 '12 at 17:51
  • @deadManN log4net is widely used. Remoting does not necessary works across machine, it can be used ( ant nowaday is mostly used ) for cross process communication – Felice Pollano Aug 17 '12 at 19:41
  • can you forward me to a related sample with my issue? which user send data, and server receive data as out put of lof4net, and not directly log it :| – Hassan Faghihi Aug 17 '12 at 20:43
  • i falled for sleep, no i'm goin to rest fully :) cya tomorrow – Hassan Faghihi Aug 17 '12 at 23:08