|
http://www.cdolive.com[^] is a good resource for everything about client and server side CDO.
_________________________________
Please inform me about my English mistakes, I still try to learn your language!
|
|
|
|
|
Hello All,
I select a Data from my databae and saved in the dataset i need to insert in this dataset new row at spacific position with the method InsertAt()
myDataSet.Tables[0].Rows.InsertAt()
Please help with example
Regards,
Hay
|
|
|
|
|
i need to call that function inside my c# application, how can i?
|
|
|
|
|
In the System.Windows.Forms.UnsaveNativeMethods class (which is marked as internal) it is defined as:
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr DefWindowProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
If you define it just like this you can use it in your own code.
/cadi
24 hours is not enough
|
|
|
|
|
why if i add this row:
[DllImport("user32.dll", CharSet=CharSet.Auto)]
i get a compile error.
What do i have to specified to the compiler?
|
|
|
|
|
You probably get a "DllImport" not found (or the like) message.
Simply add this line to you file:
uses System.Runtime.InteropServices
/cadi
24 hours is not enough
|
|
|
|
|
cadi wrote:
uses System.Runtime.InteropServices
I smell Pascal :P
David
|
|
|
|
|
er... actually it should be using
It is somwhat differnt from the uses clause in pascal.
Using is simply telling the compiler to try to prefix the namespace for any non local symbol.
The Pascal uses equivalent in C# is the References section in your solution.
Btw. my I ask why you need a call to the DefWndProc in C#?
What kind of subclassing strategy are you up to? I have not yet entered any scenario where i would like to call the DefWndProc directly since it is completely encapsulated by the framework.
/cadi
24 hours is not enough
|
|
|
|
|
cadi wrote:
The Pascal uses equivalent in C# is the References section in your solution.
yes.
cadi wrote:
Btw. my I ask why you need a call to the DefWndProc in C#?
You are asking wrong person...
David
|
|
|
|
|
|
May I ask why you need a call to the DefWndProc in C#?
What kind of subclassing strategy are you up to? I have not yet entered any scenario where i would like to call the DefWndProc directly since it is completely encapsulated by the framework.
/cadi
24 hours is not enough
|
|
|
|
|
of course, i'm overring some windows message to avoid to draw the form title bar as unactive.
It is just a hard stuff
|
|
|
|
|
Shouldn't something like this do the magic?
<code>
protected override void WndProc(ref Message m)
{
const int WM_NCPAINT = 0x0085;
if (m.Msg == WM_NCPAINT)
{
m.Result=(IntPtr) 0;
return;
}
base.WndProc (ref m);
}
the base.WndProc(ref m) calls the DefWndProc then...
/cadi
24 hours is not enough
|
|
|
|
|
i've tried and it just doesn't draw correctly the form
|
|
|
|
|
Hello,
I need to mimic, in code at run time, the behavior that takes place when ListView.AllowColumnReorder is true and the user drags/drops columns to reorder them.
To be more specific, I want to be able to edit a subitem in place (which C# doesn't allow). Someone on CodeProject wrote a ListViewEx that does this but that's overkill.
I have a simple listview with 2 columns: Name and Weight (a numeric value). I don't want Name to be editable, but I want it appearing first. I want Weight to be editable but have it appear second. I know that if I put the Weight column as the first column and then reorder columns using drag/drop, I can still edit the Weight column's data even after reordering the columns . I want to "cheat" and create the listview, then mimic the column reordering in code so that the Weight column appears second but remains editable.
|
|
|
|
|
Hey!
Intruduction:
I am using Framework 2.0(beta 2) and the System.IO.Ports.SerialPort class to communicat with serialport/USB devices.
I have built my serialport communication with Events, like this:
<br />
#region Create Connection<br />
serialPort = new SerialPort(serialPortSettings.getPort, serialPortSettings.getBoudRate, serialPortSettings.getParity, serialPortSettings.getDataBits, serialPortSettings.getStopBit);<br />
serialPort.DtrEnable = true;<br />
serialPort.RtsEnable = true;<br />
serialPort.ReceivedBytesThreshold = 4;<br />
serialPort.Open();<br />
#endregion<br />
<br />
serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_ReceivedEvent);<br />
SerialPort Settings that I use
Baud rate: 115200
Data bits: 8
Parity: None
Stop bit(s): 1
This is done by a special serialport thred, this to make sure that the main thread(the one that redraws the GUI and so on) not will be involved in the event firing of this serialport.
In serialPort_ReceivedEvent you can finde the folowing code:
<br />
lock (this)<br />
{<br />
if (RUNNING)<br />
{<br />
ThreadPool.QueueUserWorkItem(new WaitCallback(onDataReceived));<br />
currentRunningThreads++;
}<br />
}<br />
This function will be fired as soon as 4 bytes(ReceivedBytesThreshold) have been written to the serialport. As you can see, it will place a work in the ThreadPool and then make the current thread available for next event.
The onDataReceived looks like this.
<br />
if (RUNNING)<br />
{<br />
lock (this)<br />
{<br />
if (serialPort.BytesToRead > 0)<br />
{<br />
string data = serialPort.ReadExisting();<br />
<br />
<br />
if (data != null && data.Length > 0)<br />
{<br />
RemovePortHandlerRAW.Write(data);
RemovePortHandlerRAW.Flush();<br />
<br />
data = toolHandler.costmizeString(data, timeStamp, showCR_LFOnIncomingData);<br />
<br />
streamHandler.writeData(data);
<br />
if(SAVEDATATOFILE)<br />
rows = toolHandler.stringToArray(data);<br />
<br />
if (rows != null)<br />
{<br />
if (SAVEDATATOFILE)<br />
dataCollector.writeArrayToFile(rows);<br />
}<br />
}<br />
}<br />
}<br />
As you can see, am doing different things in this onDataReceived function, but the main part is: ReadExisting on the serialport and writes it to file to be abled to compare it with the file I am realy sending to my program by using CompareIt(http://www.grigsoft.com/)
TEST:
I have created a program that sends a 2 MB file with a serten data structure where every row ends with CRLF. This program sends one char at a time and this as fast as posible over a nullmodem cable (from laptop to my computer)
When the file is transfared to my computer from the laptop, it will be compared with the file I sent from my laptop, to ensure that no data is lost.
Test Result:
I have manage to find a good ReceivedBytesThreshold(decides how many byte that have to be written to the serialport before the event is fired) on the serialport that I don’t lose any data, but have a good CPU usage. I first tried 512, 256, 32. But all this value will result in some Dataloses in high speed. I then tested 4, and that works good(no data loses).
Why not choose 1? By choosing 1 in ReceivedBytesThreshold will result in a higher CPU usage.
Stress Test:
To ensure that no data will be lost I hade to made some stress tests.
Test 1:
I tried to move around a firefow window(web browser) with an andvance page loaded(like www.gamespot.com). By doing this I get 100% CPU usage, and if I do this as long as posible during my program is receiving data over the nullmodem cabel, this test showed that data are lost during stress test like this!!
Sometimes it could also result in an array that says that a Thread have been interupted, but I don’t realy know why?
Test 2:
By open a window in WindowsXp with some files in and the hold F5 pressed it will update the window so fast that the CPU usage will be 100%. But this will strangly not effect the data flow? No data is lost?
Problems:
As you can see, I cant get a sequre data transfer! I have tried other program with the same stress tests like the one here http://www.aggsoft.com/, but this works fine!
Maby this is I Microsoft problem, maby the serilaport in framework 2.0 is not reay finished yet?
Maby I shouldt buther with the outcome on Test1?
I have also tried to have a Thread loop instead of the events, but that dident help(same problem).
I realy need help here, It would be great if anyone else have the posibility to try the exact same thing.
Best Regards
SnowJim
|
|
|
|
|
The problem is with you using ThreadPool threads to write to the file. I'm pretty sure you expect the contents of the file to be in the same order as you sent. But using threads to write to the file will surely result in data misordering.
When you call ThreadPool.QueueUserWorkItem , the system assigns a thread to run the function. There is no guarantee that the function would complete before you get another serialPort_Received event. Imagine the case when the first thread has read the contents but before it writes to the file, there is another serialPort_Received event and that thread writes to the file first. Your file wouldn't have the contents in the right order then.
I suspect that's why you're getting strange results when the CPU is busy. When the CPU is relatively idle, it probably schedules your threads in such a way that each DataReceived event occurs after the ThreadPool thread has completed.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Yes i understand what you mean, but thats why i am using lock so there will hofully be a sort av queue that executes the threads in the right order?
I have also tried to place the code that writes to file in the ReceivedEvent event direcly and take away the ThreadPool Thing. Like this:
<br />
lock (this)<br />
{<br />
if (RUNNING)<br />
{<br />
FILEHANDLING CODE HERE<br />
}<br />
}<br />
but this is not helping?
I have as a mentioned, tried to switch from event to a Thread Loop, and then the data cant be read in wrong order. But this results in same dataloses as with event and Threadpool.
If i understand you right, then the data will be in the file but on a diffrent place?
The CompareIt program that i am using to compare files, will show if data is moved to other parts of the txt file. And in thes cases when i have lost data, there is simply data missing from the recived file(it also got a smaller size then it would have if its contained all the data).
BestRegards
SnowJim
|
|
|
|
|
If that doesn't help, I'm not sure what the problem is. Are you sure you always get the ReceivedEvent in the first place? Also, are you sure there is nothing wrong with the code sending the messages and that it actually has sent the messages?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Even if i shold not get the event one time, the next time it will readExisting on port, so this shold not be a problem.
And the sendingsoftware shold be working. I have used it in stress test of other serialport programs that i have downloaded, and there are no data lost?
I dont eather know way it is losing data when i am moving around window?
Cant u try det same thing? if you got a nullmodem cable?
BestRegards
SnowJim
|
|
|
|
|
If you depend on the data arriving in the exact same order it was sent, there is no easy way other than using one (1) hand-crafted thread to "listen" on the serial port.
Locking simply means that threads will not interfere with each other, it does not assure the order in which the threads will gain access.
You COULD try and use a ResetEvent in the main "queue", which is then reset in the worker-thread.
I still suggest that you try and design a single "listening worker" which should be written in a way that has it handle the events "one by one". That will cost you some speed, but is easy to understand and maintain.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Thanks for your advaice!
I have rebuilt it to one Thread like this:
<br />
RUNNING = true;<br />
currentRunningThreads = 0;<br />
<br />
dataCollector = new DataCollector();<br />
<br />
#region Create Connection<br />
serialPort = new SerialPort(serialPortSettings.getPort, serialPortSettings.getBoudRate, serialPortSettings.getParity, serialPortSettings.getDataBits, serialPortSettings.getStopBit);<br />
serialPort.DtrEnable = true;<br />
serialPort.RtsEnable = true;<br />
serialPort.WriteBufferSize = 102480;<br />
serialPort.ReadBufferSize = 102480;<br />
serialPort.Open();<br />
#endregion<br />
<br />
<br />
while (RUNNING)<br />
{<br />
if (serialPort.BytesToRead > 0)<br />
{<br />
onDataReceived();<br />
}<br />
else<br />
Thread.Sleep(1);<br />
}<br />
But the main part is that i have encreased the writeBuffersize but mainly the ReadBufferSize to 102480.
And with this settings i have now runned 4 stress tests that results in perfect matching files!
Proberly the reading buffert on 4048 was to small to handle the stress. This software may be runned on laptops later on, and there need to be some extra buffert for these. What do you think of the new buffert size? is it maby to big? or can i increase it more to be more safe?
Best Regards
SnowJim
|
|
|
|
|
Hi there...I need some hints how to read the list of files contained in a directory through C#.
Thanks
|
|
|
|
|
If you only need the names of the files you can call the System.IO.Direcoty.GetFiles method which returns an array of string.
If you need more information you first instatiate an DirectoryInfo object and then call the instances GetFiles method which returns an array of System.IO.FileInfo.
Sample:
<code>System.IO.DirectoryInfo windowsDir = new System.IO.DirectoryInfo(@"C:\windows\");
System.IO.FileInfo[] filesInDir = windowsDir.GetFiles("*.*");
</code>
/cadi
24 hours is not enough
|
|
|
|
|
Thanks man...It worked!
GaMBiT---> aND ReVeNGe WiLL Be
|
|
|
|