justin.saliba
justin.saliba

Reputation: 734

Get count from webservice

I am developing a solution in VS2010 which involves 2 projects. The first project is a normal windows form application with a button which increments an integer variable whenever it is pressed. The other project is a simple web service which returns the value of the variable. I have set the counter as both public and static as follows:

public static int count = 0;

private void AddCountButton_Click(object sender, EventArgs e)
{
    count++;
}

public static int GetCount()
{
    return count;
}

The other project has this method:

[WebMethod]
public int GetCount()
{
    return MyApplication.Form1.GetCount();
}

However, when the above method is called it always returns 0. I was hoping that someone would shed some light on the subject. Thankyou, and have a good day.

Upvotes: 1

Views: 1051

Answers (1)

Tung
Tung

Reputation: 5434

Your two projects are running as two different processes. One as a windows form, and the other as a web process. The count defined within your MyApplication.Form1 is not shared between these two processes.

@John, thank you

Upvotes: 3

Related Questions