Click here to Skip to main content
15,914,111 members
Home / Discussions / C#
   

C#

 
GeneralRe: Split a video in frames [modified] Pin
annathor22-Apr-10 0:25
annathor22-Apr-10 0:25 
GeneralRe: Split a video in frames Pin
Obaid Ahmed22-Apr-10 0:38
Obaid Ahmed22-Apr-10 0:38 
GeneralRe: Split a video in frames Pin
Obaid Ahmed22-Apr-10 1:03
Obaid Ahmed22-Apr-10 1:03 
GeneralRe: Split a video in frames [modified] Pin
annathor22-Apr-10 1:44
annathor22-Apr-10 1:44 
GeneralRe: Split a video in frames Pin
Obaid Ahmed22-Apr-10 9:43
Obaid Ahmed22-Apr-10 9:43 
GeneralRe: Split a video in frames Pin
Obaid Ahmed22-Apr-10 10:10
Obaid Ahmed22-Apr-10 10:10 
GeneralRe: Split a video in frames Pin
annathor22-Apr-10 12:08
annathor22-Apr-10 12:08 
QuestionHow to avoid a cross-thread error for a TextBox with databinding? Pin
R. vd Kooij21-Apr-10 2:25
R. vd Kooij21-Apr-10 2:25 
First question here! Been on this problem for two days now and can't seem to find a solution.. CodeProject has always been a great reference for me, so I hope you guys can help! Please find a simplified example of my application below.

Ingredients:
* public class VehicleClass
** public bool Ignition { get; set; }
** public static void SetIgnition(object vehicle)

* public partial class MainForm : Form
** TextBox "txtIgnitionStatus"

So, in the MainForm class I create an instance of Vehicle and I link the textbox on the MainForm (txtIgnitionStatus) to the Ignition property of that Vehicle class:
private VehicleClass Vehicle = new VehicleClass();
public MainForm()
{
  txtIgnitionStatus.DataBindings.Add(new Binding("Text", this.Vehicle, "Ignition"));
}


The SetIgnition method in the vehicle class a TcpClient to listen for incoming TcpPackets and sets the Ignition status of the Vehicle when necessary:

public static void SetIgnition(object obj)
{
  VehicleClass vehicle = obj as VehicleClass;

  // receives tcp packet from a NetworkStream here
  // stores tcp packet data as string in "dataString"

  switch(dataString)
  {
    case "ON":
      vehicle.Ignition = true;
      break;

    case "OFF":
      vehicle.Ignition = false;
      break;

    default:
      vehicle.Ignition = false;
      break;
  }
..
}


Here is the instantiation of the thread that handles the tcp communication:
readThread = new Thread(new ParameterizedThreadStart(VehicleClass.SetIgnition));
readThread.Start(this);

(readThread is a private class member of VehicleClass)

Now to the problem.. When the Ignition property of the vehicle class is set to "true" (ie. when a Tcp packet arrives that contains the data string "ON"), txtIgnitionStatus on the MainForm should display "True" instead of "False". It never gets that far though, because I get the following error:
Cross-thread operation not valid: Control 'txtIgnitionStatus' accessed from a thread other than the thread it was created on.


Fair enough.. I understand I'm trying to change a control that is created on the UI thread, from another thread (the thread that is created inside the VehicleClass to handle the Tcp communication). But how do I go about avoiding this error?

After spending hours searching the internet, I think I might have found a solution in using the ISynchronizeInvoke interface in my VehicleClass, to be able to Invoke the Ignition property of the class.

First of all I would like to know if that is indeed the way to go?

And if so, how should I implement the interface members BeginInvoke, Invoke, InvokeRequired, etc.?
Because when I add the ISynchronizeInvoke interface to my class, and click Implement Interface, I have the following code lines added to my VehicleClass:
public IAsyncResult BeginInvoke(Delegate method, object[] args)
{
  throw new NotImplementedException();
}

public object EndInvoke(IAsyncResult result)
{
  throw new NotImplementedException();
}

public object Invoke(Delegate method, object[] args)
{
  throw new NotImplementedException();
}

public bool InvokeRequired
{
  get { throw new NotImplementedException(); }
}

.. but I have no idea how to fill them in!? Frown | :(

I hope my problem is clear to you, and hope even more that you'll be able to help me find a solution for it!
Many thanks in advance!

René
F1RST Racing
www.f1rstracing.nl

AnswerRe: How to avoid a cross-thread error for a TextBox with databinding? Pin
R. vd Kooij22-Apr-10 9:14
R. vd Kooij22-Apr-10 9:14 
Questionpopulate combobox by passing parameter to seperate class Pin
redspiderke21-Apr-10 2:02
redspiderke21-Apr-10 2:02 
AnswerRe: populate combobox by passing parameter to seperate class Pin
Not Active21-Apr-10 2:15
mentorNot Active21-Apr-10 2:15 
GeneralRe: populate combobox by passing parameter to seperate class Pin
redspiderke21-Apr-10 3:17
redspiderke21-Apr-10 3:17 
GeneralRe: populate combobox by passing parameter to seperate class Pin
Not Active21-Apr-10 4:00
mentorNot Active21-Apr-10 4:00 
GeneralRe: populate combobox by passing parameter to seperate class Pin
redspiderke21-Apr-10 20:56
redspiderke21-Apr-10 20:56 
QuestionHOW TO RETRIVE ALL TRANSACTION from sqlserver where TODAYS DATE AS PARAMETER IN SQL QUERY.? Pin
sudhir behera21-Apr-10 1:59
sudhir behera21-Apr-10 1:59 
AnswerRepost Pin
Keith Barrow21-Apr-10 2:14
professionalKeith Barrow21-Apr-10 2:14 
AnswerRe: HOW TO RETRIVE ALL TRANSACTION from sqlserver where TODAYS DATE AS PARAMETER IN SQL QUERY.? Pin
Ashfield21-Apr-10 2:49
Ashfield21-Apr-10 2:49 
AnswerRe: HOW TO RETRIVE ALL TRANSACTION from sqlserver where TODAYS DATE AS PARAMETER IN SQL QUERY.? Pin
PIEBALDconsult21-Apr-10 3:24
mvePIEBALDconsult21-Apr-10 3:24 
GeneralRe: HOW TO RETRIVE ALL TRANSACTION from sqlserver where TODAYS DATE AS PARAMETER IN SQL QUERY.? Pin
Keith Barrow21-Apr-10 3:25
professionalKeith Barrow21-Apr-10 3:25 
GeneralRe: HOW TO RETRIVE ALL TRANSACTION from sqlserver where TODAYS DATE AS PARAMETER IN SQL QUERY.? Pin
PIEBALDconsult21-Apr-10 15:27
mvePIEBALDconsult21-Apr-10 15:27 
QuestionOrdering sub-elements in a PropertyGrid Pin
Wags21-Apr-10 0:57
professionalWags21-Apr-10 0:57 
AnswerRe: Ordering sub-elements in a PropertyGrid Pin
DaveyM6921-Apr-10 1:07
professionalDaveyM6921-Apr-10 1:07 
GeneralRe: Ordering sub-elements in a PropertyGrid Pin
Wags21-Apr-10 1:38
professionalWags21-Apr-10 1:38 
GeneralRe: Ordering sub-elements in a PropertyGrid Pin
DaveyM6921-Apr-10 2:08
professionalDaveyM6921-Apr-10 2:08 
GeneralRe: Ordering sub-elements in a PropertyGrid Pin
Wags21-Apr-10 2:15
professionalWags21-Apr-10 2:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.