i have write 5 diff words from 5 diff language into this string .
Looks to me like you have 5 different phrases, not words, and that each phrase is separate by a comma.
So first step is to break it into those parts.
After that you no longer have a problem of 5 different languages together. Instead you have a problem of identify a language (one language) given a string with one language. And then doing that five times.
I have worker threads writing to my GUI right now with the following code. My issue is that I'm getting MDA errors (ContextSwitchDeadlock and DisconnectedContext) during debugging and when I close the program, the child threads are still trying to write to controls that are nonexistent anymore, which generates errors as well.
I'm guessing I need to learn the proper way to use a delegate with multithreading/guis, so I was wondering if someone could provide some guidance and the proper/efficient way to communicate to the main form thread, from a child thread.
Using Invoke (synchronous) or BeginInvoke (asynchronous) to communicate with the UI thread is the correct approach. However, it is possible for a control to disappear while the background thread is processing, so you need to catch that exception (I couldn't find a way to guarantee that it can never happen).
I stumbled upon this link in googling and in one of the comments it was mentioned to set child thread to .IsBackground equaling true, so I did so (see brief code snip) and that seems to have eliminated the errors when closing my program. I'm glad the invoke/begininvoke are the correct way to do things, although I would still like to learn more about delegates and their proper usage.
My limited understanding of them now is that they are (at least in my project) an intermediary with the control on the main form, so that you can instruct the main thread/form thread to do something. It appears to have the ability to insert an item into the main form thread queue of what it is doing. Is that correct?
serviceMonitorThread = new Thread(new ThreadStart(serviceMonitor));
serviceMonitorThread.IsBackground = true;
If you set IsBackground, the worker thread will be killed when the main form is closed. That will solve the invoke-on-disposed-control issue but it is sometimes not what you want.
Delegates are simply typed function pointers. They are typically used to hook to events, which are some syntactic niceness around multicast delegates (i.e. the code calls what looks like one function, and several handler functions are run). They don't have anything directly to do with multithreading. Examples of non-threaded delegate usage include such obvious things as Click handlers on buttons (and all other UI events).
However, the way the Framework exposes threading functionality is either through Thread or BackgroundWorker. Thread takes a delegate to specify the method that should be run, and BackgroundWorker has several events which you can hook delegates onto.
It appears to have the ability to insert an item into the main form thread queue of what it is doing. Is that correct?
This is a decent description of the purpose of the Invoke or BeginInvoke methods. They ask the relevant thread to run a method (specified by a delegate) when appropriate.
I am writing in a listview data from an array. It is listed by the checkbox for each data alone. I would like to add by selecting a different TextBox. It's ip address in the TextBox.
in the textbox:
in the listview :
i want - for example :
I chose the first record.
If I understand the question.
1. Learn how TCP and sockets work.
2. Write code to send a message via a socket.
3. Write code to receive a message via a socket.
4. Create a message that contains the data above. Note that the message contains it. It is not just the data.
5. Put all of the above together to solve your problem.
Note that steps 1-4 have NOTHING to do with GUI elements of any kind. So your code for 2-4 must not have any text boxes, nor list views nor check boxes.
publicstruct st Staff
public Bitmap Picture; // Picturs 3x4publicstring FullName; // Full namepublic DateTime BirthDay; // Bỉthday
in my save button code
Path = @"C:\data\database.dat";
fs = new FileStream(path, FileMode.Create);
catch (Exception ex)
MessageBox.Show("Error: " + ex.Message);
BinaryWriter bw = new BinaryWriter(fs);
Staff = new Staff();
Staff.Picture = (Bitmap)pictureBox1.Image;
Staff.FullName = txtFullName.Text;
Staff.BirthDay = DateTime.Parse(mskNgaysinh.Text);
//ClsNhanvien Nhanvien; // Savefor (int i = 0; i < list.Count; i++)
Staff = (Staff)list[i];
bw.Write(Staff.Picture); // warning error: The best overloaded method match for //'System.IO.BinaryWriter.Write(bool)' has some invalid arguments
I get an error at this line
bw.Write(Staff.Picture); // warning error: The best overloaded method match for 'System.IO.BinaryWriter.Write(bool)' has some invalid arguments
I wonder in the text file can save the Bitmap type? or to switch to the new chain store? if it is correct on how?