|
|
You also didn't supply which database or catalogue you wish to connect to, so you are probably just connnected to the master database which I very much doubt has a table called test. Add a Database=[dbname]; section to your query string.
|
|
|
|
|
cmd.CommandText = "insert into test values ('" + textBox1.Text + "','" + textBox2.Text + "')";
---------------------------------------------------------------------------------------
try this one....
cmd.CommandText = "insert into test values ('" textBox1.Text + "','" + textBox2.Text + "')";
|
|
|
|
|
Hi. anybody pleas tell me how work with a-gps on windows mobile.
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
serialPort1.BaudRate = 4800;<br />
serialPort1.PortName = comboBox1.SelectedItem.ToString();<br />
serialPort1.Open();<br />
timer1.Enabled = true;<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message);<br />
}<br />
<br />
}<br />
<br />
private void timer1_Tick(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
string data = serialPort1.ReadExisting();<br />
listBox1.Items.Add(data);<br />
}<br />
catch(Exception ex)<br />
{<br />
MessageBox.Show(ex.Message);<br />
}<br />
}<br />
<br />
this code work with gps device, but if I run app on phone with a-gps - it crash with OutOfMemoryException
|
|
|
|
|
the only line here could couse to crash with exception is: listBox1.Items.Add(data); . You put it in timer, and it will crash after certain time.
I do not know about windows mobile, but I know that in 32bit of windows have a limit to 4,294,967,295 numbers of items before it reach limit. You attempt to hold all data in memory. This is a bad design
|
|
|
|
|
this code work on windows mobile 6.0 more then 3 hours without pause. but when I run it on windows mobile 6.5 and connect to a-gps device it crash.
|
|
|
|
|
I cant point to what exactly is problem, but is the only infromation you get that it is exception OutOfMemoryException?
You will probalbly get more information if you use exe with debugging information
|
|
|
|
|
I wont to know haw van I take coordinate from a-gps. Code that I post work excellent with GPS device and didn't work with a-gps.
When I take it string data = serialport.ReadExisting() app crashed with OutOfMemoryException
|
|
|
|
|
did you tried stancrm suggestion?
If it doesn't help, i do not know how to help you
|
|
|
|
|
|
hmmm this error only on windows mobile 6.5 and mobile phone
6.0 or 6.1 or PDA work good
error on string
string data = serialPort1.ReadExisting();
or serialPort1.ReadLine();
maybe I must read data from com port and gps use other method?
|
|
|
|
|
Hi,
I have developed an application to test some devices. The idea is to send and recieve message by device on each device in parallel. I can set for each device a timing (e.g. 100ms) between each message sending.
For that I have used the thread with time but it seems that is not the good idea because if the execution of the function need more time than the time between each send, the call is stacked into the pool execution. So when I stop the test execution, the application continue to send message due to the queue of execution in the pool.
I think that I use to many thread for one application and the runtime is very slow due to context switching or something like that.
Have an idea about the good possibility to do this application ?
I think maybe that is better if I use one service by device and the application is connected to each service to retrieve some status information. What do you think ?
Thank you for your answer...
|
|
|
|
|
Hi,
your question is not clear at all, please provide more and more accurate information, such as:
- "some devices": what are they? what is their function? how many? how do they connect?
- "to send and recieve message": how many? how long should testing a single device take?
- "I have used the thread with time": what does that mean? and which kind of thread? a Thread instance? a ThreadPool.QueueWorkItem? a BackgroundWorker? ...
- "the call is stacked into the pool execution": huh? what pool would that be?
One thing I can say is a service is probably not the right way to tackle the problem.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Hi,
Thank your for your answer.
The type of the devices and their functions and how many devices have no importance. The goal of my application is to test an embedded board. So the board have many device depending of the board and different type of devices. You can think that we have between 1 to 5 differents devices. But my application have a low interface for each type of devices and so handle the access to the device by a same interface to have an abstraction of the type of device to the upper level (of course implementation is different).
My problem is at the higher level.
For my test I send message through a device (in my case but you can abstract this problem with a network area where we need to send message to another application). The message received at the other side is read and returned by the same link that as been recieved. When the message is coming back to my application I check it to control that have no corruption in the data and so report the information into a log file and an window of statistic.
This is made in parallel and we have no limit of time i.e. it can be run 1h, 10h, 1 day. The user run the test and stop it by press a button. We can assume any idea of the time that have the board to take to return the message to the application, this is depending of the device and the runtime of the onboard side.Maybe is never returned in case of problem in the board side (no more memory, busy for a moment). This is the reason of we have a thread to send and one to read and the statistic of the number sending/recieved.
My first conception is as follow:
1 thread by devices for sending message
1 thread by devices to wait/read message received
1 thread to log and check message recieved to a file/window report.
The goal is to have an independant thread for each output and input. We want to send message in continue through each output.
I use the timer and timer delegate for the thread. At first I use a Thread object but this is not precise of when he run. With the Timer, we can ask it to wakeup at every x ms (e.g. each 100ms) to send a message. So I see that the Timer work with a ThreadPool.
What do you suggest otherwise that the service ?
|
|
|
|
|
if I understand all that correctly, you have a single communication means, and the PC does not really have much to compute, so I would use:
- either a single thread to do it all;
- or exactly one thread for each device.
The major issue seems to be to dispatch the incoming messages, so the result can be stored, logged, counted, and followed by a new outbound message. That can be handled by a data-driven approach and does not require separate threads at all. Threads are expensive: they each need memory (including a stack), and thread switching takes time too.
If you want all that to reside in a service, you could do that, it making sense depends on what people are supposed to do or not to do to the PC in the mean time.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
To explain more, I have one example. I have 3 (but it can be more) port COM. With my application the goal is to do at the same time:
Send message every 50ms to COM1 (time interval is defined by the user in a user interface)
Send message every 75ms to COM2
Send message every 50ms to COM3
For sending, I use one Timer for each port COM (= 3 thread),each thread wake up at the time defined by the user (i.e. one at 50ms, one at 75ms and the last one at 50ms).
So if you send message, you receive answer. It seems that we need a thread for each port COM to receive data (we don't know when the data is coming back). The thread of reception sleep until a data is received. When a message is received, the thread wake up, we push the message into a list and the thread sleep to the next reception.
Another thread check the list of message in reception and log the info.
I know that the thread is expensive and this is my problem. Now I use 2 thread by devices (one for sending, one for reception) and one thread to check the data and log it. This is the reason for what I want to change for a service. I think that one service by device can be used and so reduce to max 2-3 thread for each service. I think that the service have one process for him.
|
|
|
|
|
Hi,
0.
You should have provided this information and more from the start, you have been wasting time.
1.
having P identical processes with T threads each isn't any better than having 1 process with P*T threads; it is the same amount of work for the Windows kernel, and takes the same amount of stack space.
2.
one normally doesn't need a thread to output something. Output most often can be handled synchronously.
3.
one often needs some asynchronous code to receive data; it could be a thread performing a blocking read, it could also be an event running on some thread, e.g. SerialPort.DataReceived. You may want to read this[^].
4.
Windows timing isn't always very accurate; you may want to read this[^]
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Hi,
Thank you
0. Yes, sorry! I have not take into account the difficulty to understand my need.
1. Of course the memory and stack space is not reduced, it seems that is greather with more process but perhaps I have more time execution by thread. Each process have a limited time in the Windows kernel and this time is splited into the number of thread.
2. Probabily, I need to check that because I have one processor and is not possible to send at the same time at two or more differents output.
3-4 thank you for the link! I have not the time now to read that, but later I do it.
I see that you have a good knowledge about the "low level" and I am interested to clarify one more point.
Have you one link for the event in c#. I use some event to report information (e.g. device error, reception of data) and it seems that is need to be used carrefuly. When a event is generated, it is the thread where the event is generated that execute the call or a new thread (one thread by listner of an event?) ?
|
|
|
|
|
lord_laurent_r wrote: I use some event to report information
if that refers to the event keyword, then yes they are synchronous, no extra threads involved.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
no, it refer to a delegate type for hooking up change notifications
|
|
|
|
|
I've got the following code running and the idea is that a row in the DB has a coloured letter in it to denote customer or supplier etc. The first row i highlight seems to vanish, the background for the row is blue and the selected index is set so that's all nice but the text disappears. If i click the row a second time the row unselects and the text comes back.
public partial class CompanyListControl : ListBox<br />
{<br />
int _previousIndex = 0;<br />
public CompanyListControl()<br />
{<br />
InitializeComponent();<br />
this.DrawMode = DrawMode.OwnerDrawFixed;<br />
}<br />
protected override void OnDrawItem(DrawItemEventArgs e)<br />
{<br />
base.OnDrawItem(e);<br />
if (!DesignMode)<br />
{<br />
e.DrawBackground();<br />
if (this.SelectedIndex == e.Index)<br />
{<br />
if (_previousIndex != e.Index)<br />
{<br />
InvalidateItem(_previousIndex);<br />
DrawSelected(e);<br />
_previousIndex = e.Index;<br />
}<br />
}<br />
else<br />
{<br />
DrawUnselected(e);<br />
}<br />
}<br />
}<br />
public void InvalidateItem(int index)<br />
{<br />
if ((index < 0) || (index >= this.Items.Count))<br />
return;<br />
object InvalidatedObject = this.Items[index];<br />
this.Items.RemoveAt(index);<br />
this.Items.Insert(index, InvalidatedObject);<br />
}<br />
private void DrawSelected(DrawItemEventArgs e)<br />
{<br />
if (e.Index == -1) return;<br />
int RowWidth = e.Bounds.Width;<br />
Font f = new Font("Arial Black", e.Font.Size);<br />
Size s = TextRenderer.MeasureText("C", f);<br />
int SalesPos = 0;<br />
float PurchasePos = s.Width * 0.7f;<br />
float TextPos = PurchasePos * 2;<br />
int VerticalPos = e.Bounds.Top;<br />
e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, Brushes.White, TextPos, e.Bounds.Top);<br />
e.Graphics.DrawString("C", f, Brushes.Red, SalesPos, VerticalPos);<br />
<br />
}<br />
private void DrawUnselected(DrawItemEventArgs e)<br />
{<br />
int RowWidth = e.Bounds.Width;<br />
Font f = new Font("Arial Black", e.Font.Size);<br />
Size s = TextRenderer.MeasureText("C", f);<br />
int SalesPos = 0;<br />
float PurchasePos = s.Width * 0.8f;<br />
float TextPos = PurchasePos * 2;<br />
int VerticalPos = e.Bounds.Top;<br />
e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, Brushes.Black, TextPos, e.Bounds.Top);<br />
e.Graphics.DrawString("C", f, Brushes.Red, SalesPos, VerticalPos);<br />
}<br />
protected override void OnSelectedIndexChanged(EventArgs e)<br />
{<br />
base.OnSelectedIndexChanged(e);<br />
this.Invalidate();<br />
}<br />
}
Does anyone have any ideas what might be wrong? I've added and removed all sorts of bits from the code and it doesn't seem to change the behaviour very much at all (to the point that I put some break points in just to check that this code was actually being run)
Thanks
Russ
|
|
|
|
|
It was wery hard to find your code problem, but i did find it. Use this:
protected override void OnDrawItem(DrawItemEventArgs e)
{
base.OnDrawItem(e);
if (!DesignMode)
{
e.DrawBackground();
if (this.SelectedIndex == e.Index)
DrawSelected(e);
else
DrawUnselected(e);
}
}
Also InvalidateItem function removed item and inserted, witch coused to be OnDrawItem called. You have created infinitive loop.
Edit: also I do not think if (!DesignMode) is nesesery, because you want to see items in designer mode if you add items using property windows. This is normal behaviour for ListView
|
|
|
|
|
thank you,
not at my desk at the moment but i'll try that fix in the morning.
The invalidate thing was added because i thought maybe it needed to redraw to fix it, adding it seemed to make no difference at all, I should have taken it out before posting
Thanks again,
Russ
|
|
|
|
|
Russell Jones wrote: i thought maybe it needed to redraw to fix it
Actualy you only draw an items. For that usaly happens in OnDraw function.
|
|
|
|
|
Please go through...
class Test
{
Console.WriteLine("1:Add\n2:Sub\n3:Mult:\n4:Div");
Console.WriteLine();
Console.WriteLine("Press 9 to Exit or Enter to Continue ");
string s=Console.ReadLine();
....
}
My query is that when I enter the "ENTER" key, it does go ahead but it also does the same for the other keys except 9, for which it exits from the Program.
Hope so I will get a solution
|
|
|
|
|