Click here to Skip to main content
15,885,141 members
Home / Discussions / C#
   

C#

 
Questionvarchar(max) vs varchar(50) Pin
Mogaambo17-Sep-08 23:03
Mogaambo17-Sep-08 23:03 
AnswerRe: varchar(max) vs varchar(50) Pin
leppie17-Sep-08 23:08
leppie17-Sep-08 23:08 
AnswerRe: varchar(max) vs varchar(50) Pin
Mogaambo17-Sep-08 23:26
Mogaambo17-Sep-08 23:26 
GeneralRe: varchar(max) vs varchar(50) Pin
leppie17-Sep-08 23:42
leppie17-Sep-08 23:42 
GeneralRe: varchar(max) vs varchar(50) Pin
Pete O'Hanlon18-Sep-08 0:30
mvePete O'Hanlon18-Sep-08 0:30 
QuestionHow to show event of a user control in property window Pin
Guru Call17-Sep-08 22:50
Guru Call17-Sep-08 22:50 
AnswerRe: How to show event of a user control in property window Pin
Simon P Stevens17-Sep-08 23:30
Simon P Stevens17-Sep-08 23:30 
QuestionTrouble with Invocation, serial port Pin
introuble217-Sep-08 22:41
introuble217-Sep-08 22:41 
Ok, i am still having some trouble with the code. I have a controller on the other side with a thermometer and keyboard etc.
I am sending the temperature from there to my form. It normally works fine.

The only time it gives me an error is when the first thing i do (after turning on the controller) is click "show temperature" on my screen form. Then the error that occours is the following:
Invoke or BeginInvoke cannot be called on a control until the window handle has been created.

It also says:
TargetInvocationException was unhandled.
Exception has been thrown by the target of an invocation.

Could it be that the forst time data is in some kind of wrong format? How to make sure that the window handle will be created before BeginInvoke?

Sample code: namespace WindowsFormsApplication1
{


public partial class Form1 : Form
{

int ledStatus = 0;
int r = 2;
System.IO.Ports.SerialPort sp = new System.IO.Ports.SerialPort();



public Form1()
{
InitializeComponent();
sp.PortName = "COM5";
sp.BaudRate = 19200;
sp.Parity = Parity.None;
sp.DataBits = 8;
sp.StopBits = StopBits.One;
sp.ReadTimeout = 5000;
sp.Open();
sp.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
}


void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
this.BeginInvoke(new Action(UpdateData), sp.ReadExisting());
}

public void UpdateData(string character)
{
if (r == 1)
{
string ajutine2 = "0";

ajutine2 += character;


int stringToInt = Convert.ToInt32(ajutine2);
for (int y = 0; y < 1000; y++) ;
if (stringToInt > 100)
progressBar1.Value = stringToInt;


double intToDouble = Convert.ToDouble(stringToInt);
double ajutine3 = intToDouble / 10;

string doubleToString = Convert.ToString(ajutine3);

ekraan1.Text = "";
ekraan1.Text += "Temp: ";
ekraan1.Text += doubleToString;
ekraan1.Text += " *C";


}
else if (r == 2)
{
for (int y = 0; y == 5000; y++) ;
ekraan1.Text += character;
}

}

... }
AnswerRe: Trouble with Invocation, serial port Pin
leppie17-Sep-08 22:51
leppie17-Sep-08 22:51 
GeneralRe: Trouble with Invocation, serial port Pin
introuble218-Sep-08 0:31
introuble218-Sep-08 0:31 
GeneralRe: Trouble with Invocation, serial port Pin
leppie18-Sep-08 0:35
leppie18-Sep-08 0:35 
GeneralRe: Trouble with Invocation, serial port Pin
introuble218-Sep-08 1:49
introuble218-Sep-08 1:49 
GeneralRe: Trouble with Invocation, serial port Pin
leppie18-Sep-08 3:14
leppie18-Sep-08 3:14 
AnswerRe: Trouble with Invocation, serial port Pin
Alan N18-Sep-08 1:46
Alan N18-Sep-08 1:46 
GeneralRe: Trouble with Invocation, serial port Pin
introuble218-Sep-08 2:07
introuble218-Sep-08 2:07 
GeneralRe: Trouble with Invocation, serial port Pin
Searril18-Sep-08 9:01
Searril18-Sep-08 9:01 
GeneralRe: Trouble with Invocation, serial port Pin
introuble219-Sep-08 2:02
introuble219-Sep-08 2:02 
GeneralRe: Trouble with Invocation, serial port Pin
Searril19-Sep-08 10:14
Searril19-Sep-08 10:14 
QuestionUser searchbox and RegEx best-practice Pin
ArneKruger17-Sep-08 21:56
ArneKruger17-Sep-08 21:56 
AnswerRe: User searchbox and RegEx best-practice Pin
leppie17-Sep-08 22:27
leppie17-Sep-08 22:27 
GeneralRe: User searchbox and RegEx best-practice Pin
ArneKruger17-Sep-08 23:37
ArneKruger17-Sep-08 23:37 
QuestionProper use of Tag property Pin
Mycroft Holmes17-Sep-08 21:47
professionalMycroft Holmes17-Sep-08 21:47 
AnswerRe: Proper use of Tag property Pin
N a v a n e e t h17-Sep-08 21:55
N a v a n e e t h17-Sep-08 21:55 
GeneralRe: Proper use of Tag property Pin
Mycroft Holmes17-Sep-08 22:08
professionalMycroft Holmes17-Sep-08 22:08 
AnswerRe: Proper use of Tag property Pin
Pete O'Hanlon17-Sep-08 21:58
mvePete O'Hanlon17-Sep-08 21:58 

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.