There's TWO things going on here...
The UI thread cannot interact with activity originating in a different thread when controls are involved (such as your tab control). To avoid cross-threading problems, use a construct like this...
private void DoSomethingOnTheUiThread()
{
Dispatcher.BeginInvoke((Action) (() =>
{
// your code goes here...
Window w = new Window();
w.Show();
}));
}
...where the 'Dispatcher' gets the System.Windows.Threading.Dispatcher the window is associated with. Every UIElement has a dispatcher for this purpose. BeginInvoke schedules the delegate to run on the UI thread.
A related SO question gives more insight here: WPF Cross Thread Object Access
...and here How to deal with cross-thread access exceptions?
For your other issue, let's look at your code...
Task.Factory.StartNew(() =>
{
NewWindow.selectingTab(ClientName);
using (var ns = cl.GetStream())
using (var br = new BinaryReader(ns))
using (var bw = new BinaryWriter(ns))
{
Console.WriteLine("Message from client is " + br.ReadString() + " from " + clientName); } });
In your commentary you point out that 'NewWindow' is a class. But you are calling an instance method of 'NewWindow', not a static method of 'NewWindow'. So the compiler has complained about it.
To call an instance method, you must first create an instance, like this...
NewWindow nw = new NewWindow();
nw.selectedTab("some name");
The c# forefathers made the syntax 'NewWindow.selectedTab' to mean a static method. I don't know which of these you want to implement, but you'll need to pick one that is consistent with your usage.
Relevant docs are here: http://msdn.microsoft.com/en-us/library/aa645766(v=vs.71).aspx
**
When a method is referenced in a member-access (Section 7.5.4) of the
form E.M, if M is a static method, E must denote a type containing M,
and if M is an instance method, E must denote an instance of a type
containing M.
**