PDA

Click to See Complete Forum and Search --> : [3.0/LINQ] Window1 dosnt contain a definition for 'Invoke'


Rattlerr
Feb 11th, 2007, 10:16 AM
Here is the line of code with the Invoke in it::

this.Invoke(new delUpdateHistory((this.UpdateHistory)), para);

The Line Below is the Delegate for the above::

public delegate void delUpdateHistory(string str);

Which goes to this section of code::

public void UpdateHistory(string str)

{

// some code

}



this.Invoke produces this error::

Error 1 'iSCS.Window1' does not contain a definition for 'Invoke'

Invoke from what i have read is supported by .NET 3.0 Framework so the above code should work,unless i'm missing something.The code works fine in .NET 2.0 so, i'm not sure what is wrong here :ehh:

So how do i go about fixing this?? :confused:

jmcilhinney
Feb 11th, 2007, 05:01 PM
What type of object is iSCS.Window1? Is it a System.Windows.Forms.Form or a new .NET 3.0 type, like a System.Windows.Window? If it's the latter, does that class have an Invoke method?

Rattlerr
Feb 11th, 2007, 05:17 PM
Its a new .NET 3.0 Type System.Windows.Window as for an Invoke Method this is what i have by Default but not sure how to write it out..

private void Invoke(delUpdateHistory delUpdateHistory, object[] para)
{

}

I removed "throw new Exception("The method or operation is not implemented.");"

If you want to see all the code related to the Delegate i will post it up..Thxs for the help jmcilhinney :)

jmcilhinney
Feb 11th, 2007, 05:50 PM
I wasn't implying that you should create your own Invoke method. Invoke is a method of the System.Windows.Forms.Control class that marshals a delegate to the thread that owns the control's handle and then invokes it. If the .NET 3.0 Window class doesn't have an Invoke method then it's for a reason. Either you don't have to worry about which thread you access WPF controls from or else there's some new mechanism to do it. My advice is to try to do what you're doing without the delegate and see what happens. If it works then I would assume that there's no issue and you don't have to care about threading issues with WPF controls. If it throws an exception then see if the IDE provides advice as to how to fix the issue. If it does then you're laughing. If it doesn't then it's time to do some research.

Rattlerr
Feb 11th, 2007, 06:14 PM
Here are the 2 Sections of code i'm currently working with i have commented out the Delegate but need some help with getting the "UpDateHistory" to update the ListBox for each user that enters. So i need some help replacing the commented line of code so the "public void UpDateHistory(string str)" updates..
Here is the 1st block of code

//public delegate void delUpdateHistory(string str);
public void ReceiveMessage(IAsyncResult ar)
{

try
{
int bytesRead;
bytesRead = client.GetStream().EndRead(ar);
if (bytesRead < 1)
{
return;
}
else
{
string messageReceived;
int i = 0;
int start = 0;
while (data[i] != 0)
{
if (i + 1 > bytesRead)
{
break;
}
if (data[i] == 10)
{
messageReceived = partialStr + System.Text.Encoding.ASCII.GetString(data, start, i - start) + Environment.NewLine;
object[] para = { messageReceived };
//this.Invoke(new delUpdateHistory((this.UpdateHistory)), para);
Here is the Invoke i have commented out..
start = i + 1;
}
i += 1;
}

if (start != i)
{
partialStr = System.Text.Encoding.ASCII.GetString(data, start, i - start);
}
}
client.GetStream().BeginRead(data, 0, System.Convert.ToInt32(client.ReceiveBufferSize), ReceiveMessage, null);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}

Here is the 2nd Block of Code Related to each other::
public void UpdateHistory(string str)
{
if (str.StartsWith("[Join]"))
{
int nameLength = str.IndexOf("]", 6);
RoomLB.Items.Add(str.Substring(7, nameLength - 7));
return;
}
else if (str.StartsWith("[Left]"))
{
int nameLength = str.IndexOf("]", 6);
try
{
RoomLB.Items.RemoveAt(RoomLB.Items.IndexOf(str.Substring(7, nameLength - 7)));
}
catch (Exception ex)
{
}
return;
}
else if (str.StartsWith("[Usrs]"))
{
string[] users = str.Substring(7, str.Length - 8).Split(',');
RoomLB.Items.Clear();
foreach (string user in users)
{
RoomLB.Items.Add(user);
}
RoomLB.Items.RemoveAt(RoomLB.Items.Count - 1);
return;
}
else if (str.StartsWith("[File]"))
{
string[] users = str.Substring(7, str.IndexOf("]", 7) - 7).Split(',');
int index = str.IndexOf("]", 7) + 2;
string filename = str.Substring(index, str.Length - index - 3);
DialogResult response;
response = System.Windows.Forms.MessageBox.Show("Do you want to download the file " + filename, "Download", MessageBoxButtons.YesNo);

if (response == System.Windows.Forms.DialogResult.Yes)
{
SendMessage("[Send_File][" + users[0] + "," + CommandTB.Text + "]");
FTP_Receive(filename);
}
return;
}
else if (str.StartsWith("[Send_File]"))
{
string userIP = str.Substring(12, str.Length - 15);
FTP_Send(fullfilename, userIP);
return;
}
else if (str.StartsWith("[Talk]"))
{
str = str.Substring(str.IndexOf("]", 7) + 1);
conStatus.AppendText(str);
}
}