|
engsrini wrote: But i read this BackgroundWorker class will not have any cross-threading issues. Is it right?
You still have to synchronise the threads regardless of how the thread is wrapped up.
|
|
|
|
|
The BackgroundWorker will not allow any cross-thread operations and will throw an exception if you try to do so.
You still need to have a basic understanding of how threading works even when using the BackgroundWorker . If you are trying to change the button image as the result of either progress or completion, you need to do so using either the ProgressChanged or RunWorkerCompleted events. (If you use ProgressChanged, make sure to set the WorkerReportsProgress property to true.
See http://msdn2.microsoft.com/en-us/library/system.componentmodel.backgroundworker(vs.80).aspx[^] for more details.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Hi there,
I have a DataGridView bound to a BindingSource, and this BindingSource is bound to a BindingList of custom objects.
The list is updated from another thread, and when it tries to update the DataGridView it (understandably) crashes because the control was created in the main thread while the list was updated in a worker thread.
I know you can use Invoke to solve cross threading problems but in this case I have no clue on what event I should use Invoke. I dont even know if I should be looking at the BindingSource or the DataGridView itself.
I've ran out of ideas and Im finding this pretty frustrating, any help would be greatly appreciated.
Thanks in advance!
|
|
|
|
|
Hello,
I have a program which is always running on user's computer.
And I would like to add an item to windows context menu (shell menu), with option to Backup a file (it's not a problem).
After user right clicks some file in explorer and then clicks "Backup this file", is it possible to send somehow file path argument to already running program?
|
|
|
|
|
You can do this if it exposes an interface for doing so, such as COM, .NET Remoting, or a Web Service, etc. It would be rather difficult, if not impossible in some cases, to gain access to the memory space of the application otherwise.
only two letters away from being an asset
|
|
|
|
|
Not something I've done, but try looking into MSMQ messaging. .Net provides support in System.Messaging.MessageQueue. It wasn't totally clear from your post, but assuming that you are writing a shell extension in c#, you could have your shell extension add a message and your running program read the messages from the message queue.
TopCoderJax
|
|
|
|
|
The WM_SENDMESSAGE message is the easiest way to do this. As others have said, if you mean without changing the source code of the program you want to send the argument to, the answer is no. But, if you want to change the program to work with a shell extension, then that's the way I would do it
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks very much for all answers, was very helpful. Did it with messaging, because it was easy and fast
|
|
|
|
|
I'm brand new to C#. I just want to create a simple progam that will write data to a file on the hard drive (some text plus some variables). Does anyone have a "hello world" type program that writes a message to a text file rather than the output window? Thanks!!
Harley
|
|
|
|
|
using(StreamWriter sw = File.AppendText(@"c:\Date.txt"))
{
sw.WriteLine("Hi");
sw.WriteLine("Today's date: "+ DateTime.Now.ToShortDateString());
}
Have a look at the c# beginner's articles[^] in this site.
|
|
|
|
|
I have being written about webserver http1.0 by C#,now begin telnet I connect to webserver,after that I write GET /index.html HTTP/1.0
please,I want to ask you:I have to use which class,which method to test format of this String(GET /index.html HTTP/1.0)
to know it format of httpRequest
thanks
help me
|
|
|
|
|
For serious string parsing check out the Regex class. Example here.[^]
|
|
|
|
|
How do I use grayscale values to determine the color of pixels read from an image
tony-yeyo
|
|
|
|
|
I don't understand your question. When you read a pixel, you get a Color value, what do you want to do with that?
---
single minded; short sighted; long gone;
|
|
|
|
|
well I plan to draw a graph of the pixels against the grayscale so I wanted a way to group the pixels corresponding to the grayscale values. Like 0-255 is black-white respectively on the grayscale.
So how do I determine that this pixel is of a particular color according to the grayscale?
tony-yeyo
|
|
|
|
|
Just take the average of the red, green and blue color components.
---
single minded; short sighted; long gone;
|
|
|
|
|
Grayscale images contain 1/3 of the data in a color image. As such, you could write an algorithm that makes guesses as to the colors in a greyscale image, but you're never going to get back to the right colors, and it would be hard to even come close enough for the resultant image to look vaguely similar.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
What I am trying to do is create a new picturebox everytime you left click on the screen and delete the one you are on when you left click on one.
This is the code I have.
if (c == panel1)
{
if (e.Button == MouseButtons.Left)
{
//Get picturebox from unUsedBoxes to Create a new box
int position = unUsedBoxes.Count - 1;
if (position >= 0)
{
System.Windows.Forms.PictureBox p = (PictureBox)unUsedBoxes[position];
unUsedBoxes.RemoveAt(position);
usedBoxes.Add(p);
p.Location = new System.Drawing.Point(e.X, e.Y);
p.Size = new System.Drawing.Size(100, 50);
p.Show();
p.MouseDown += new MouseEventHandler(mouseDown);
p.MouseUp += new MouseEventHandler(mouseUp);
p.MouseMove += new MouseEventHandler(mouseMove);
}
else
{
MessageBox.Show("You have exceeded the maximum number of selections", "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
else
{
if (e.Button == MouseButtons.Right)
{
//Delete box
usedBoxes.Remove(c);
unUsedBoxes.Add(c);
panel1.Dispose();
}
}
}
the code compiles but the picturebox is never created.
|
|
|
|
|
A control is most useful when you add it to some container...
|
|
|
|
|
I already have this code in the Designer
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(100, 50);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
And this code in the On Load
usedBoxes = new ArrayList();
unUsedBoxes = new ArrayList();
unUsedBoxes.Add(pictureBox1);
do I need to specify more than that a parent?
|
|
|
|
|
a control only "works" in a UI when added to the form's hierarchy of controls,
as in myForm.Controls.Add(myControl)
check this in the documentation, and in the code generated by Visual Studio's Designer !
|
|
|
|
|
i can't find the way to use thread with method have some param?
plz, help me out! thanks
|
|
|
|
|
Create struct or class to contain the parameters and use it.
only two letters away from being an asset
|
|
|
|
|
Hey all !
First of all let me start by saying I'm new to C# and programming what so ever..
I have a Excel sheet that I read lines from. Each line has 15 cells with numbers between 1-70 of random combinations.
My purpose is to hash every single line to a single result. The result is stored in an array.
I'm doing so by performing XOR between the cells' content (casting them to bytes).
This also gives me the luxery of not having to deal with the order of the numbers.
However, here's the problem. I'm getting the same XOR result for different types of numbers (how obvious).
For Example:
13^17^21^22^23^25^26^27^29^31^46^53^55^60^63 = 61
5^9^14^20^27^28^32^35^38^41^43^50^58^61^62 = 61
Is there any better solution for doing what I want ?
Be very appretiative if someone could help me out ...
Thanks !
|
|
|
|
|