これを実現するローカル Web サービスを作成できます。
Web サービスを作成するには、次のようなことを行う必要があります。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
public int myInt = 0;
[WebMethod]
public int increaseCounter()
{
myInt++;
return myInt;
}
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
Web サービスを実行すると、次のように表示されます。

別のプログラム/スレッド (この場合はコンソール アプリケーション)
次のようにそのサービスに接続できるはずです。



最後に、作成したサービスの URL を入力します。

これで、このコンソール アプリケーションから Service1 クラスのオブジェクトを次のようにインスタンス化できます。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication36
{
class Program
{
static void Main(string[] args)
{
localhost.Service1 service = new localhost.Service1();
// here is the part I don't understand..
// from a regular class you will expect myInt to increase every time you call
// the increseCounter method. Even if I call it twice I always get the same result.
int i;
i=service.increaseCounter();
Console.WriteLine(i.ToString());
// you can recive string data as:
string s = service.HelloWorld();
// output response from other program
Console.WriteLine(s);
Console.Read();
}
}
}
この手法を使用すると、ほとんど何でも他のアプリケーションに渡すことができます (シリアライズ可能なものなら何でも)。したがって、この Web サービスを 3 番目のスレッドとして作成して、より整理することができます。お役に立てれば。