0

This question will be very vague since I have no idea where to begin. I've searched, but the examples are composed of projects that are much more complex than what I need.

We have two Windows Forms: FormWriter and FormReader. FormWriter needs to set the text of TextBox in `FormReader'.

At one point someone suggested WCF. This way, FormWriter can send FormReader a message with the string for the TextBox.

Does anyone have a link that can point me to a link that's related to this issue? What I've found is much more complex than what I'm looking for. I understand that one form would be the server while the other are the clients.

The biggest obstacle is that each form will be running on a different devices at different locations.

Thanks.

fdkgfosfskjdlsjdlkfsf
  • 3,165
  • 2
  • 43
  • 110
  • Are these forms part of the same project? Is the FormReader and FormWriter inside the same process or is supposed to work like a chat program? – Conrad Frix Jun 23 '16 at 19:36
  • Each form will be running on a different devices at different locations. – fdkgfosfskjdlsjdlkfsf Jun 23 '16 at 19:39
  • 1
    Then please change "form" to "application" in your question, as it now looks like you want to use WCF within the same application. – CodeCaster Jun 23 '16 at 19:40
  • I just want two forms to communicate with each other. They can both be in the same project if need be. But they're not two applications. – fdkgfosfskjdlsjdlkfsf Jun 23 '16 at 19:43
  • 1
    If they are in the same application, you don't need to use WCF. You can simply use some events to notify the other form. But if they are in different applications, based on [your previous question](http://stackoverflow.com/questions/37993243/alternative-to-polling-database-in-windows-form) it seems [`SqlDependency`](https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency(v=vs.110).aspx) is what you need. Anyway, To learn WCF, you can take a look at tutorials in WCF [Getting Started Tutorial](https://msdn.microsoft.com/en-us/library/ms734712(v=vs.110).aspx) page. – Reza Aghaei Jun 23 '16 at 19:44
  • 2
    "The biggest obstacle is that each form will be running on a different devices at different locations." If they are running on different devices, then they are different applications, or at least different *instances* of the application. It's not at all clear what you're trying to accomplish here.... – Tim Jun 23 '16 at 19:47
  • @RezaAghaei, They're the same application but each Form is in a different device. Would `SqlDependency` still work? – fdkgfosfskjdlsjdlkfsf Jun 23 '16 at 20:27
  • When you say *they are running on different devices at different locations* it means they are in different instances; they are running in different processes. So as an option for synchronizing those instances, you can use a notification mechanism. `SqlDependency` is an option. Using `WCF` is another one. – Reza Aghaei Jun 23 '16 at 20:48
  • @RezaAghaei, It seems `SqlDependency` is similar to `FileSystemWatcher`, except that it's for databases instead of files. – fdkgfosfskjdlsjdlkfsf Jun 23 '16 at 21:09
  • @rbhatup Yes, somehow. – Reza Aghaei Jun 23 '16 at 21:11
  • If you want, you can add a simple code snippet of how `SqlDependency` would be used and how `OnChange` would look like to check a sql table, and I'll accept it as an answer. Thanks. – fdkgfosfskjdlsjdlkfsf Jun 23 '16 at 21:18
  • Thank you for your kind offer :) Since using `SqlDependency` is just one of options and an answer which describes how to use it should contains many details, I prefer to leave a good link for you: [Detecting Changes with SqlDependency](https://msdn.microsoft.com/en-us/library/62xk7953(v=vs.110).aspx) which contains better descriptions than what I can share :). But maybe I post an answer for your other question which is specifically asks for an alternative for polling database. – Reza Aghaei Jun 23 '16 at 21:24
  • @RezaAghaei, I posted a question directly related to `SqlDependency` here: [link](http://stackoverflow.com/questions/38024866/sqldependency-onchange-not-firing-in-winform) – fdkgfosfskjdlsjdlkfsf Jun 25 '16 at 04:50
  • Fortunately your question has been answered. I did +1 to your question and the answer :) – Reza Aghaei Jun 25 '16 at 08:14

2 Answers2

0

You can use WCF for this, but I think the overall solution is out of the scope of a simple answer on here.

Basically what you want is a Service running in one application, and the other application call it. (For two-way communication you can use one of the duplex bindings such as NetTCPBinding which will allow you to do two way messages)

You can also do all of this in code using the ServiceHost class, pass it the Address, Binding and Contract information and Start it. Then on your other application connect to it as a client.

For a basic understanding of the WCF Duplex communication you probably want to take a look at this: http://www.codeproject.com/Articles/491844/A-Beginners-Guide-to-Duplex-WCF

It shows you how to setup the service using the "Service Reference" option in Visual Studio which is probably the simplest way to do it, but everything you can do in the wizard, you can do manually in code with more flexibility..

If you have any problems, post some code up and I'll be happy to help further

Robert Perry
  • 1,906
  • 1
  • 14
  • 14
0

A WCF based chat application would be a perfect example for your requirement. There are tons of examples in CodeProject regarding this topic. Please go through some WCF based chat app demo projects for the solution that you require.

Ozesh
  • 6,536
  • 1
  • 25
  • 23