|
Why don't you let each thread open its own connection?
|
|
|
|
|
thank you frank but i think you didnt understand my problem.
when i open a connection to a database with sqldatareader, i can not open another connection to that database or anyoneelse untill previouse connection will be close.
but in multi threading its maybe happen. what should i to do to avoid to this critical error????
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
mr.mohsen wrote: i can not open another connection to that database or anyoneelse untill previouse connection will be close.
In that case you don't need multiple threads.
If you use multiple threads you need to synchronise access to the
connection so only one thread can use it at a time...may as well
just use one thread.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I think Frank has the correct solution. Your code does not show where you create the SQLCommand object and assign it a connection. Each connection can have only 1 datareader open. If you instantiate a command and connection IN each thread it will work.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hello 4 all
How can i get all of the forms in the project For exable:
foreach (Control cont in this.Controls)
MessageBox.Show(cont.Name + " " + cont.Text);
but instead of getting the controls i want to get all of the form in certin project
thx
|
|
|
|
|
Hi,
If this is a MDI application, iterate through main window's MdiChildren property
Mika
|
|
|
|
|
Hello
I am basically a Micro controller programmer trying to learn C# for controlling my devices through serial port.(USB is next target).
I have seen serialport control and its events in C#2008. Also I went through some example projects in Code project. They seem to be not using that control. They are using coding only using Serialport class of dot net.
Let me express some of my basic doubts. (My doubts arise out of my comparatively low speed and sequential programming experience in Micro controllers- so it seems to me)
Suppose I need to do a task when I received 20 bytes from serial port. I understood that data received is in a buffer. But I need to act only when a particular number of bytes is received. Or a particular character or null is received.I have seen the time out property, but in my case data may come at different quantity. So time out may not be practical. How I can realize this requirement?
In another situation sometimes a packet of 30 bytes arrives in a strech - means sequentially and stops. Means that packet ends and there will be a pause of substantial time before next packet comes. Here I need to get informed that one packet received and stopped, so my task will jump in. In micro controllers I use interrupts and all. Here it seems to me that more easy and flexible options are available. but I don't get the clue.
Any guidelines for where I to look or follow which method?
With Regards
Roy Thomas
"..this file is known as source file probably because it is a source of frustration and anxiety!" - Chuck Sphar - In book 'C# 2005 for Dummies'.
modified on Saturday, August 9, 2008 10:57 AM
|
|
|
|
|
Have you tried using the DataReceived event from the System.IO.Ports.SerialPort?
|
|
|
|
|
Thanks for the reply.
I am trying that now. But It will create an event when each data received- means for each byte. But I need to act only when 20 bytes are received.
So read the buffer on each event, append it to a user array, and check for the end of packet-- is this the suitable and possible method?
With Regards
Roy Thomas
"..this file is known as source file probably because it is a source of frustration and anxiety!" - Chuck Sphar - In book 'C# 2005 for Dummies'.
|
|
|
|
|
MSDN says
"The DataReceived event is not guaranteed to be raised for every byte received. Use the BytesToRead property to determine how much data is left to be read in the buffer."
What does this mean? If the event is not guaranteed how can we get the complete and correct string coming through serial port?
With Regards
Roy Thomas
"..this file is known as source file probably because it is a source of frustration and anxiety!" - Chuck Sphar - In book 'C# 2005 for Dummies'.
|
|
|
|
|
I think I have found some clue.
To get a particular number of bytes we can set the receive threshold as ..say 20. Then receive event will be triggered when serial port receives 20bytes.
Unlike in Micro controllers windows cannot give events (Interrupts ) guaranteed for every byte received. I have tried by making a device connected to serial port which sends some lengthy strings. If I send bytes with a few 10s of milliseconds gap from the embedded device, I am getting an event for every byte. But if I send a continuous data stream with no delay in between, events are triggered at no uniform intervals. sometimes 8 bytes sometimes 40 bytes. even if receive threshold is set to 1 byte.
So what I found as the best method is make receive threshold as 1 byte, on receive event use BytesToRead method to get all bytes received so far and append it to a string. also on every event clear a timer count to 0. When the packet ends the timer count will not gets cleared in time so that it will climb up and creates a user event.(working on that)on the event can check for a EOF to confirm a valid packet.
Why this complex machine cannot give a timely event while a small Microcontroller can do it in correct time?
With Regards
Roy Thomas
"..this file is known as source file probably because it is a source of frustration and anxiety!" - Chuck Sphar - In book 'C# 2005 for Dummies'.
|
|
|
|
|
|
How can i count the number of characters used out of provided in a text box.I mean when a user enters some text in a text box provided how can i show he has used x out of y characters with each keystroke in real time?Can anyone provide code in C#?Thanks
|
|
|
|
|
Set the MaxLength property of your textbox to some value (like 200), then in the TextChanged event of the textbox you can write some information into a label if you like:
private void textBox1_TextChanged(object sender, EventArgs e)
{
label1.Text = string.Format("You use {0} out of {1} characters", textBox1.Text.Length, textBox1.MaxLength);
}
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Please tell me the link for learning the mobile programming
|
|
|
|
|
try to search in google
there are a lot of good results on a few first pages...
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
Hi,
I want to trigger an event every time I type something in a textbox using Onchange events.
The code im using is
IHTMLElementCollection elcol1 = doc.getElementsByTagName("input");
foreach (IHTMLInputTextElement iel in elcol1)
{
HTMLInputElementClass ee = iel as HTMLInputElementClass;
if (ee.value!= null && ee.IHTMLInputElement_type.Equals("text"))
{
ee.HTMLInputTextElementEvents2_Event_onChange += new HTMLInputTextElementEvents2_onChangeEventHandler(ee_HTMLInputTextElementEvents2_Event_onchange);
}
}
For every text element it enters into the "if" block but the "ee_HTMLInputTextElementEvents2_Event_onchange" function is not called. How can i trigger the event? Please help!
|
|
|
|
|
Hi, I am trying to use the third party VideoCog componet with C# and I need to copy a image frame? Videocog drops the frame into an rgb array in memory and I can then fast process the pixels using pointers.
How can I create another copy of the frame from memory so that I can also access that via another pointer?
Thanks...
1.
private void videoCogControl1_FrameReady(double SampleTime, IntPtr pBuffer,
2.
int BufferSize, int Width, int Height)
3.
{
4.
unsafe
5.
{
6.
byte* p = (byte*)(void*)pBuffer;
7.
int nWidth = Width * 3;
8.
for (int y = 0; y < Height; y++)
9.
{
10.
for (int x = 0; x < nWidth; x++)
11.
{
12.
p[0] = (byte)(255 - p[0]);
13.
p++;
14.
}
15.
}
16.
}
17.
}
|
|
|
|
|
Have you tried the Marshal.Copy[^] method from the interop namespace?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks for the reply, I am very new to C# and I am just working off the Videocog tutorials, do you have an example of how Marshal.Copy works?
|
|
|
|
|
|
Thanks, I got it to work, but there must be an faster/easyer way to copy a block of memory?
This is what I did to get it to work with Marshal.ReadByte, it gives me p2 which I can use on the copied image:
byte[] bytes = new byte[BufferSize];
for (int i = 0; i < BufferSize; i++)
bytes[i] = Marshal.ReadByte(pBuffer, i);
fixed (byte* pTmp = bytes)
{
System.IntPtr pBuffer2 = new IntPtr((void*)pTmp);
byte* p2 = (byte*)(void*)pBuffer2;
}
|
|
|
|
|
Use Marshal.Copy instead of Marshal.ReadByte . Now you are making a method call for every byte that you copy, that is bound to be slow.
Why are you converting the pointer to an IntPtr value, then back to a pointer? Just copy the pointer:
fixed (byte* pTmp = bytes) {
byte* p2 = pTmp;
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks, I tried to use Marshal.Copy but I could not get it to work, could you please show how to implement it?
Cheers,
|
|
|
|
|
Have you tried the C++ forum?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|