|
Just to prove your theory I commented out all references to 'faxing' (this was the other thread in my form) & I still get this error.
So now I am confused
Lady Programmers are a rare breed!
|
|
|
|
|
What about the if-clause? Doesn't that access chkShowSparesMatrix?
|
|
|
|
|
Yeah I suppose it does.
Even if I comment out the single method which uses System.Threading to send a fax (this method isn't always called in code anyway), I still get the 'cross threading operation not valid error message.
I have no idea why
Lady Programmers are a rare breed!
|
|
|
|
|
Hi,
here is my standard reply on cross-thread problems, I hope it helps:
Controls are not thread-safe, hence they should be touched (that is: their methods or properties called) only by the thread that created them, which normally is the main thread (aka GUI thread). Creating some controls on a different thread is unlikely to be successful, since all Controls get linked somehow: they reside on Forms, Forms are related to each other (by Parent, by Z-Order, etc), so normally all are created on a single thread.
If you violate the “don’t touch Controls from another thread” rule and are running .NET version 2.0 or above you will get an InvalidOperationException (“Cross-thread operation not valid”), which should be remedied by changing the code.
Do not set Control.CheckForIllegalCrossThreadCalls false, since that does hide the exception but does not cure the fundamental flaw in your code, so it just postpones the moment of failure, which typically will show as a non-responsive and possibly badly painted GUI.
Here are some ways to get another thread:
- explicitly launching a Thread instance
- exclicitly delegating some work to a ThreadPool thread
- using a BackgroundWorker; a BGW is a separate thread with the advantage that two of its events (ProgressChanged and RunWorkerCompleted) execute on the GUI thread; however the bulk of the work normally is handled in the DoWork handler which runs on a distinct thread.
- using timers other than System.Windows.Forms.Timer; the Forms timer ticks on the GUI thread, all other use different threads to handle the periodic event;
- using asynchronous input/output, such as the DataReceived event of the SerialPort class
Any of these touching a single method or property of a Control is sufficient to create havoc; there are 5 exceptions:
- the InvokeRequired property
- the Invoke, BeginInvoke, EndInvoke and CreateGraphics methods (the latter only if the handle for the control has already been created).
If there is a need to touch the Control from another thread, one must use an Invoke pattern, which basically looks like this:
public void SetText(string text) {
if (myControl.InvokeRequired) {
myControl.Invoke(new Action< string >(SetText),
new object[] {text});
} else {
myControl.Text=text;
}
}
|
|
|
|
|
Hi Everybody There!
I need help regarding Reading & Sending SMS Through SonyEricsson Mobile Modem.. I did alot of research and found some helpfull topics on the Net but still i am missing the .How actually C# Application Do Communicate with The GSM modem..
I will be thankful for any body who helps me out in this problem
Regards
A.Q.Ghouri
|
|
|
|
|
search for serial port communication in Google
--------------
Before Writing A C# Application U have to know about the Properties of your Modem like Buad Rate, parity,Flow control..,
and also know about the AT commands.
Write Your Application Using Serial Port Class
Thanks
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
thanks buddy for letting me know that how to do that.. i have all the stuff but now i have to focus on how to deal with it.. infact i have 2 problems.. some gsm does not support Text mode,and some do so i have to make a flexible app which will delt both of them..
|
|
|
|
|
|
Thanks alot buddy really help full.....
|
|
|
|
|
Hi,
I use the following code for drawing line on a panel, but after few seconds the line disappear.
Can someone help with this?
Graphics formGraphics = panel1.CreateGraphics();
formGraphics.DrawLine((Pens.Red, p1, p2);
Thanks in advance.
Lune
|
|
|
|
|
Hi,
that indicates you didn't paint it in the right way.
there are several steps to correctly draw something so it becomes visible on the screen:
1.
decide upon what object you want to draw; it normally is a Control (e.g. a Panel) or a
Form itself. I prefer to add a Panel to a Form, then draw on the Panel.
2.
create some variables (Rectangle, struct, class, whatever) that hold the parameters of
your drawing. For a rectangle that could be top and left coordinate, and width+height,
or just a Rectangle. etc.
3.
create a Paint handler (either add your own paint handler to the Paint event, or
override the OnPaint method) for that Panel, and do all your drawing in there,
using the Graphics class and your variables.
4.
when you want to change things, modify the variables and call Panel.Invalidate() or
one of its overloads (for selective invalidation).
5.
If you want to animate things, perform the move (step 4) inside the Tick handler
of a Windows.Forms.Timer
BTW: if you need to create some objects (Fonts, Pens, Brushes, ...) either keep them
alive in class members (hence create them only once); or create them inside the Paint
handler and don't forget to call Dispose() on them.
|
|
|
|
|
And you have the nerve to suggest that I am verbose!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Fortunately I do have a small collection of standard replies available, this is the one I give for all paint problems unless more specific symptoms ask for a more personalized answer.
|
|
|
|
|
Thanks,
But do you mean that if I want a persistant line I should keep the point variables all along the program?
and also you suggest that the line should be drawn in the OnPaint event but is it the only way? I need to create the line as a response to an other events, so what is the right way?
Thanks,
|
|
|
|
|
lune12 wrote: what is the right way?
I just indicated the right way.
if you want to change the drawing, then change the data and call Control.Invalidate() to request an automatic repaint.
|
|
|
|
|
Thanks, it's working but isn't it a waist of time to redraw all the line each time that the paint event is invoked?
|
|
|
|
|
you could reduce the amount of work executed by taking into account the clipping data that is present in the PaintEventArgs/Graphics. IMO that is worthwhile only in special cases, like complex paintings that need frequent repaints (e.g. as in games, which probably get programmed quite differently anyhow).
|
|
|
|
|
CreateGraphics is temporary. Use e.Graphics and the Form.Paint event instead. You also appear to have a syntax error (two brackets in front of Pens.Red)
|
|
|
|
|
|
i have already saved username,password in login table.if i entered username,password in login_form, valid user only access that form.how will i do.plz help me
|
|
|
|
|
Write a Stored Proc which will accept two params i.e. your entered username and password, then compares it with the database and returns the status (success/failure). Execute this SP for authentication.
Before doing that go to the nearest book store, buy some good book and learn the basics.
|
|
|
|
|
|
demetter wrote: plz give me the code
Firstly, thats not how it works here. You write the code, and when it doesn't work we help with specific problems. Otherwise, you never learn anything.
Secondly, how are we meant to do that without knowing anything about your database - most people on here are not mind readers, although it does help with some of the questions.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
this code i have used.database is msaccess(mdb)
private void btn_login_Click(object sender, EventArgs e)
{
try
{
string UserName,password,txtPassword;
UserName = txt_user.Text.ToString();
password = txt_pwd.Text.ToString();
//Query = "insert into Login (UserName,txtPassword ) values ('" + UserName.ToString() + "','"+ password.ToString() +"' )";
//daSet = dd.ExcuteDataSet(Query.ToString());
//MessageBox.Show("Successfuly Saved..!");
Clear();
if (UserName == ds.Tables["Login.UserName"].ToString())
if (password == ds.Tables["Login.txtPassword"].ToString())
{
MessageBox.Show("correct");
}
else
{
MessageBox.Show("incorrect");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
modified on Friday, April 17, 2009 8:38 AM
|
|
|
|
|
You need to learn a bit about sql before you go any further. Try searching CP for aricles about using access and c#. Do you understand how a database stores data and how to retreive it? It doesn't look like it from the above.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|