|
Dear All, I have following code to run 10 thread at same time
for(byte i=0; i<10; i++)
{
Thread t=new Thread(new ThreadStart(runAction));
t.IsBackground=true;
}
void runAction()
{
if (InvokeRequired)
{
BeginInvoke(new run(runAction));
return;
}
}
If i uncomment the code Application.DoEvent() then it will give me the responsive interface, but also it starts the last action first, while i want to run them concurrnetly and then the second last and so on to first.
if i comment the code Application.DoEvent() then only one (first thread) runs and others are stack, like one finish then another start and so on.
I want to run thread concurrently and i would like have my UI working?
what is wrong with my code?
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
You're not showing enough of the code. What is "run"? Is this code sitting on a form or in a seperate class?
Also, did you know that every thread you launch costs you 1MB of RAM and is an expensive operation? Is there any particular reason for doing this??
After all that, you're not launching the same operation on 10 seperate threads. Each of your threads is calling the same function ON THE UI THREAD. So it's not suprising that your UI is frozen during this time. All you did was launch the call on a background thread, which farmed out the work of "runAction" back to the UI thread.
You do the work in the background threads and then if they have any updates to the UI that need to be done, they can Invoke a method that does the update on the UI thread.
|
|
|
|
|
Well, this is real code.
foreach(ListViewItem prv in des.lProvinces.CheckedItems)
{
if (prv.Text.Equals("All"))
continue;
pmuAccessPath=string.Format("{0}\\{1}\\NSPDatabase.mdb",des.DestinationFolder,prv.Text.Trim());
if (Directory.Exists(Path.GetDirectoryName(pmuAccessPath)))
Directory.Delete(Path.GetDirectoryName(pmuAccessPath),true);
Directory.CreateDirectory(Path.GetDirectoryName(pmuAccessPath));
if (!File.Exists(pmuAccessPath))
File.Copy(des.SourceAccessPath,pmuAccessPath);
Triplet triplet=new Triplet(prv.Text,pmuAccessPath,prv.Tag);
Thread t=new Thread(new ParameterizedThreadStart(runMultiple));
t.IsBackground=true;
t.Start((object)triplet);
}
delegate void run(object var);
void runMultiple(object varr)
{
if (InvokeRequired)
{
BeginInvoke(new run(runMultiple),varr);
return;
}
Triplet variables=varr as Triplet;
string prv=variables.First.ToString();
Finish fin=new Finish();
pnlControls.Controls.Add(fin);
fin.Dock=DockStyle.Top;
fin.lblProvince.Text=string.Format("Province : ({0})",prv);
fin.lblProvince.Refresh();
string query=string.Empty;
byte tableCount=43;
string pmuAccessPath=variables.Second.ToString();
int prvId=Convert.ToInt16(variables.Third.ToString());
}
based on my idea, all thread should run at same time, but in this case it doesent.as i told n msg that if i remove the code "Application.DoEvent()" the interface is totaly stack, but if i use that code then every thing is responsive, while my last action is done first and then it continues.
but bothering is that only one thread runs at atime, i can see running threads in progress bar.
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
how to connect 9 pin serial port plug to itself so tha one can recive the data in the 2nd Pin andtransmit in 3rd pin.
I am not able to send or recive the data throuth 9 pin plug serial port.
|
|
|
|
|
Connect pin 2 to pin 3, and unless there is some hardware handshaking, it should work. If handshaking is used, then connect 7 to 8, then 6 to 1 and 4 if required. See here for pinout[^]
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I tried i am only able to recive but i am not able to write serial port.i mean i am not able tosend the data.Below is the code snip.
if (serialPort1.IsOpen == false)
{
this.serialPort1.Open();
}
this.serialPort1.Write("3F 50 52 40");
|
|
|
|
|
A couple of things:
1) Are you aware that
serialPort1.Write("3F 50 52 40"); will write 11 bytes, not 4?
2) Are you sure that you wired the connector the right way? The pin numbering is normally molded into the connector with a "1" beside pin one. If you are recieving ok, then you are presumably connected to something else as well, which would imply you have wired the connector wrong for loopback.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hi,
if you need to test some serial port software, you can do so without requiring actual serial port hardware, by using virtual ports. Here[^] is an example for you; I used the com0com virtual driver successfully, it brings you a pair of virtual serial ports that seem connected by a null modem cable.
|
|
|
|
|
After writing to the serial port i am reciving an error of writing timed out i am using the HandShake Requestto send,I am not geting the problem
|
|
|
|
|
your statement isn't very clear; I think it tells me you are using hardware handshaking, and something is wrong with it. If the sender needs a permission to send, and the other party doesn't provide it, the sender is bound to time out (and if he were to ignore the lack of permission, the message would be lost as the other party will probably ignore it, being not ready to receive anything).
You might try with a very simple communication: no handshaking, and short messages, far apart. When that works, add handshaking. When that works, use any message length and frequency you want.
|
|
|
|
|
Judging by the timing of the messages, he isn't listening to anything anyone is saying. I think he's looking for a simple code fix and doesn't really have any hardware attched to the port at all, nor does he have the virtual COM ports you suggested installed.
|
|
|
|
|
Dave Kreskowiak wrote: he isn't listening to anything anyone is saying
Yeah. I have seen such pattern of behavior before, mostly in people from one and the same country. Writing is good, however I wish the would learn to read and interact too.
|
|
|
|
|
Hi.
As people have said, don't use hardware handshaking if you don't have to. It's harder to use hardware handshaking. But, it prevents buffer overruns. As people know, Windows is not a real-time OS. Hardware handshaking is much faster than using a higher level software implementation. In some cases, you can not tolerate a buffer overrun, and you want to use the fastest way you can. Serial communication is semi-slow to begin with.
You'll need to make sure that the correct signals are connected in the cables. Most serial cables do not include the handshake signals! Also, you need to know the wiring of which pins on ConnectorA go to which pins on ConnectorB.
I strongly recommend that you get and use an RS232 breakout box! It'll save you a lot of time. Also, you should have at least a light logic probe that can handle the RS232 voltage levels that you're using. You can use a DVM (Voltmeter). There are a number of low-cost USB "logic analyzers" that can interpret RS232 signals. The handshaking signals would often be displayed separately. I'm not sure if the MSOs show/decode the RS232 handshake signals. I like the Tek MSOs the best.
This will help you get started with using RS232 handshaking:
http://www.google.com/search?q=rs232+hardware+handshaking[^]
http://www.google.com/search?q=rs232+breakout+box[^]
Good Luck!
______________
Joe
|
|
|
|
|
I know that the OP isn't in America. Still, low-cost USB Logic Analyzers that support RS232 decoding, check out ebay:
Business & Industrial > Electrical & Test Equipment > Test Equipment > Logic Analyzers
http://business.shop.ebay.com/Logic-Analyzers-/97231/i.html[^]
Here is the one that I use, and a number of other consultants use:
http://www.pctestinstruments.com/[^]
Note: The USB Logic Analyzers do not support doing a trigger on a specific data word. So, you would/could trigger the start bot of the RS232. The interpretation is done by post processing software. However, an MSO like the Teks, often support doing a trigger on a specific data word (e.g. trigger on RS232 data value of 0x43).
|
|
|
|
|
Hi this is to be done in c#. Please help
(Events)
1. Write a program which includes a class named Numbers, for which Print is a member function to print numbers 1 to n. When the number of elements printed becomes equal to n, an event is invoked to stop printing numbers, showing a message “Limit Exceeded”.
(Indexers)
2. Create a class Student with RegNo, Name & Marks. Include Indexer, Create 5 instances of Student, and display them.
(FileSystem)
3. Create a Windows application to select a file from the system and display its properties Name, Size, Dates etc
4. Create Windows Application to read from an existing file and write to a new file. There should be 2 radio buttons FileStream & Stream. If FileStream is selected the file reading and writing should be performed using FileStream and if Stream is selected file reaing and writing should be performed using StreamReader & StreamWriter.
5. Simulate a Notepad Application. (Hint: Use RichTextbox, Dialogbox controls, Classes from System.IO namespace etc.)
|
|
|
|
|
ayushibasant wrote: Hi this is to be done in c#. Please help
(Events)
1. Write a program which includes a class named Numbers, for which Print is a member function to print numbers 1 to n. When the number of elements printed becomes equal to n, an event is invoked to stop printing numbers, showing a message “Limit Exceeded”.
(Indexers)
2. Create a class Student with RegNo, Name & Marks. Include Indexer, Create 5 instances of Student, and display them.
(FileSystem)
3. Create a Windows application to select a file from the system and display its properties Name, Size, Dates etc
4. Create Windows Application to read from an existing file and write to a new file. There should be 2 radio buttons FileStream & Stream. If FileStream is selected the file reading and writing should be performed using FileStream and if Stream is selected file reaing and writing should be performed using StreamReader & StreamWriter.
5. Simulate a Notepad Application. (Hint: Use RichTextbox, Dialogbox controls, Classes from System.IO namespace etc.)
Nobody here is going to do your homework for you, for free.
Even if we could be bothered, read the bit above, where it says "How to get an answer to your question". Notice the bit about your tutors?
We don't mind helping people, but you have to show us you have been trying, and got stuck. Have a go! What's teh worst that could happen - you might actually be able to do it yourself... If not, then ask again, when you are stuck on a specific element (but read the rules above first).
It's only Chriss' new rules that prevent a pile of abuse.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
a. listen in class!
b. Thou Shall Use Google!
1. how about: "public event EventHandler FooEvent"?
2. how about: "public int this[int index] { get {} set {} }"
3. how about: "open VS, New Solution, WPF Application" ?
4. how about copying other's work? Just google for such an app and modify it? Perhaps on codeproject?
an interesting of interesting exemple: http://www.codeproject.com/KB/files/[^]
5. see 4
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Interesting, but unfortunately you forgot to tell us what have you tried so far, and where *exactly* are you stuck, so that we can guide you from there.
Awaiting your reply...
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
How to close a MDI parent Form???
|
|
|
|
|
Click the close button, select File -> Exit, call Application.Exit ???
only two letters away from being an asset
|
|
|
|
|
Dear All,
I have very simple select statement as
select * from tblA
tblA contains following columns
Id int PK Identity(1,1)
Name varchar(50)
when i create insertstatement from SqlCommandBuilder as
SqlDataAdapter da=new SqlDataAdapter("select * from tblA",connection)
SqlCommandBuilder b=new SqlCommandBuilder(da)
string query=b.GetInsertCommand().CommandText;
it generats the statement
insert into tblA ([Name]) values (@p1)
how can i add identity column into the select statement of CommandBuilder or how can i create the statement which it should contain identity column too?
Note: I am only talking of make insert statement from SqlCommandBuilder
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
Abdul Rahman Hamidy wrote: how can i add identity column into the select statement
Abdul Rahman Hamidy wrote: Note: I am only talking of make insert statement
Are you ask for the insert or select?
For select just ask for it;
SELECT id, Name FROM tblA
For insert;
SET IDENTITY_INSERT ON;
INSERT INTO TblA(ID, Name) VALUES(...)
SET IDENTITY_INSERT OFF;
only two letters away from being an asset
|
|
|
|
|
thx for reply, what i want to save the insert statement of SqlcommandBuilder into string.
in fact what i am doing is, i want to migirate all sql server tables data into ms access.
i have same tables structure and name in ms access. i want to get all records of MS SQL tables into MS Access Tables and make 34 Access Database from that.
i just need to get the insert statement of Sql Table and assign it into MS Access.
like
OleCmd.CommandText=sqlCmdBuilder.GetInsertCommand().CommandText;
OleCmd.ExecuteNonQuery();
Note: In MS access only the autoincrement fields are changed to Not To Increment.
values should come from Sql Tables.
if you guys have any better solution, i would really appreciate.
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
Abdul Rahman Hamidy wrote: i want to migirate all sql server tables data into ms access.
Why???
If you need a local datastore try using SQL Server Express rather than Access
only two letters away from being an asset
|
|
|
|
|
I created Windows Service in C#.net.
In Windows service I want to connect to remot sql server 2000 But I get Error "Login failed for user(sa)".
In Windows Service first I retier data from local database but i cannot insert that data into database of remote sql server.
|
|
|
|
|