|
Use something like a volatile bool quit , set it to true and periodically check if it's true in your thread.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
Using VS2005
I have three comboboxes with the purpose of selecting a member from a lookup table and inserting their meberID into another table. Each combobox has the same links ie:
The datasource -> nameLookuptable
The displaymember -> memberName
The valuemember -> memberID
The databindings - selected value will link to another table that is to record the memberID although I have tried leaving this blank to test the workings but this doesn't make any difference to the problem.
The problem I have is that selecting a member from the drop down list in any one of the comboboxs results in all three changing.
I've tried everything to isolate the problem but can't.
On another form in the same project, I have no problems with the configuration of the comboboxes as above.
Any suggestions welcomed.
Glen Harvy
|
|
|
|
|
If three combos have the same data source, they will do this. The solution is to set the data source in code, and to use the Clone method to make copies of the data source, so they point to different objects, but with the same data.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
There will be at least 15 combos required on the page - do I need 15 clones!
I'm confused because the combos works fine on a different tabbed page on the same form !
Glen Harvy
|
|
|
|
|
Glen Harvy wrote: do I need 15 clones!
In my experience, I think so. Or a better design, why do you need 15 combos that have the same info in them ?
Glen Harvy wrote: I'm confused because the combos works fine on a different tabbed page on the same form !
I'd be surprised if the code was the same, I've had the same problem, and making copies of the array ( in my case ) being used for the combos was what solved it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: n my experience, I think so. Or a better design, why do you need 15 combos that have the same info in them ?
The form requires the user to select which member did what - in this case propose, second motions etc.
I'm beginning to think the problem lies elsewhere and may be linked to the bindingnavigator.
I can't believe that you need to clone when what I want to do is really standard out of the box stuff.
Glen Harvy
|
|
|
|
|
Do a simple test. Create a form with as many combo boxes as you like. Create a List, and make it the data source. They will all change selection. Clone the list for each data source. They won't. At least, that's how it works here.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Yep - that's how it works here - unbelievable!
I'm now creating individual bindingsources to work around this - at least it works.
I'd clone if I knew how to
Glen Harvy
|
|
|
|
|
Clone is one of the four magic methods that Object ( and therefore every .NET class ) has. So, if your old code is
combo1.DataSource = x
combo2.DataSource = x
combo3.DataSource = x
change it to
combo1.DataSource = x.Clone()
combo2.DataSource = x.Clone()
combo3.DataSource = x.Clone()
Now, in C# I need to cast the object returned to the correct type, but as VB.NET is weakly typed, you may not need to do that.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
For each duplicate combobox, create a unique BindingContext.
this.comboBox1.BindingContext = new BindingContext();
this.comboBox2.BindingContext = new BindingContext();
...
Otherwise they all inherit the default BindingContext from the forms I believe.
|
|
|
|
|
Hi Friends
I have experience in building Embedded Linux Firewall Linux using NETFILTER Hooks...
Can Any friends over here direct me how to Build a packet filter firewall application using C#.NET..
I have used SHARPPCAP library and WINPCAP
But I dont Know how to DROP a packet according to the rule using this libraries
Hari
|
|
|
|
|
which .dll files are these ??
These are no in the System32....
Are you using some customised DLLs????
<marquee>nishu
|
|
|
|
|
hi,
i have datagrid that contain the data from table named carlicensfines which get information abount fines
i want to check which fines can the customer pay i add the checkbox to datagrid by using asp but i want to do it by using c# windosapplication
ashrafhakiem
|
|
|
|
|
Hello
If you use .Net 2.0 framework you can add a DataGridViewCheckBoxColumn ate the begining of your DataGridView.
Regards
|
|
|
|
|
Hi!
is there any problem with having a public static property with both get and set access. I know there is but not sure where i might have problem
|
|
|
|
|
There shouldn't be any problems.
The only thing is that if you want to do it with vars so you need static vars, and can't work with the vars you have on the same object.
|
|
|
|
|
No, there is no problem with having that. There might be a problem if you expect it to do something that it doesn't, though.
A public static property can only access static members of the class, no instance members.
All threads in the application share the property, so if you use a multi threaded environment, like ASP.NET, you can't store separate values for each user.
---
b { font-weight: normal; }
|
|
|
|
|
But, of course, if you use a static property in a multi threaded environment, you need to remember to use locking to avoid race conditions.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello. Is it possible to connect to a wireless card and/or send data over the network the card is connected to using C#?
I love to program!
|
|
|
|
|
what kind of network are you asking about? if it is an IP network you can easily access it using System.Net name space; this is heavily documented - try searching here first http://www.codeproject.com/cs/internet/[^].
If it's important to you that the network is wireless or specifically if you need to comunicate directly with the network card, than i'm not sure c# is the best approach.
there are no facts, only interpretations
|
|
|
|
|
I've set up a background worker thread to load images from a web service, but while it does that, my program becomes unresponsive. I call the method to load the image in my DoWork delegate, doesn't that mean it happens on the other thread ? I also had a progresschanged delegate, it just sets a position in a progress bar. With this in, it died right away. I took it out and it seemed to work, but when I gave the program focus, it immediately became unresponsive. In both cases, it's Not Responding in the Task Manager, and the UI no longer responds to any events. I'm running a debug version, in the IDE, when I break, it's always on the line in the other thread that loads an image from the web service. The main thread is not doing any work of any kind, in theory.
What might I be missing here ?
threadLoadCase = new BackgroundWorker();
threadLoadCase.DoWork += new DoWorkEventHandler(threadLoadCase_DoWork);
threadLoadCase.ProgressChanged += new ProgressChangedEventHandler(threadLoadCase_ProgressChanged);
threadLoadCase.WorkerReportsProgress = true;
threadLoadCase.RunWorkerCompleted += new RunWorkerCompletedEventHandler(threadLoadCase_RunWorkerCompleted);
void threadLoadCase_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
if (e.UserState != null)
lblLoadingCase.Text = "Downloading " + e.UserState.ToString() + ":";
progressLoading.Value = e.ProgressPercentage;
// Without this, the progress bar never showed at all.
Application.DoEvents();
}
void threadLoadCase_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (!string.IsNullOrEmpty(e.Result.ToString()) && !firstFeedMe)
{
firstFeedMe = true;
filmStrip1.Clear();
OpenFiles(Directory.GetFiles((string)e.Result));
ResetDisplayMode();
}
}
void threadLoadCase_DoWork(object sender, DoWorkEventArgs e)
{
lblLoadingCase.Visible = progressLoading.Visible = true;
Application.DoEvents();
progressLoading.Value = 0;
e.Result = LoadCase(RequestIDs[0]);
}
and the guts of the method:
ImageInfo[] images = inbox.GetRequestImages(req.IdRequest);
int percentstep = 100 / (images.Length + 1);
int percent = percentstep;
foreach (ImageInfo inf in images)
{
// threadLoadCase.ReportProgress(percent, req.PatientName + req.OwnerLastName);
string imageFile = Path.Combine(folder, inf.ItemName);
if (!File.Exists(imageFile))
{
ImageData data = inbox.GetImageCompressed(inf.IdImage, dicomCompressionTypes.cmpJPEG2000);
using (FileStream fs = new FileStream(imageFile, FileMode.OpenOrCreate, FileAccess.Write))
{
fs.Write(data.Image, 0, data.Image.Length);
fs.Close();
}
}
percent += percentstep;
}
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
CG, you gotta set the example, man, and use <pre> tags around that code!
Just skimming the code, a couple things jump out at me. First, you're calling Application.DoEvents everywhere. In my experience, this is a bad idea, because you can start getting things like event handlers out of order if the DoEvents is called in certain places.
The lblLoadingCase is a label? If so, don't update that in DoWork. Same goes for the progress bar. The DoWork method is called on a background thread, the ProgressChanged and RunWorkerCompleted will be called from the UI thread. Accessing WinForm controls on a background thread is asking for trouble; VS2005 will actually throw an exception if this happens under the debugger.
As far as the freezing goes, my only guess is the ProgressChanged event is getting hammered; flooded with calls. Each call will require the UI thread to execute it obviously, so the if the UI thread is constantly busy, the UI won't have a chance to paint.
Here's what I recommend: first narrow the problem down, see if it's the ProgressChanged handler, let's see if it becomes responsive again. If it's responsive when you don't call ReportProgress, then you need to update the UI in a manner that allows the UI to still repaint itself. I have such a solution if you're interested; it's actually pretty easy to implement. But first try removing calls to ReportProgress, and see if the app is responsive again, then let me know.
If it's not that, it may be that your DoWork handler is being called on the UI thread, which would indicate you're not starting the work correctly or the worker wasn't initialized on the UI thread.
|
|
|
|
|
Judah Himango wrote: First, you're calling Application.DoEvents everywhere
Only because I'm trying to make the UI work at all, it's not being updated right now.
Judah Himango wrote: The lblLoadingCase is a label? If so, don't update that in DoWork.
Ah - good point. I AM in a debug build, but perhaps it's freezing when it means to be blowing up...
Judah Himango wrote: As far as the freezing goes, my only guess is the ProgressChanged event is getting hammered; flooded with calls
No, that's not possible. Each call is just before a web service call that takes a while. I also set a breakpoint to see, and it's not happening, only one call ever happens, although the UI does not repaint itself.
Judah Himango wrote: I have such a solution if you're interested; it's actually pretty easy to implement
OK - I'd be keen to see it, thanks.
I'm also going to put Console.WriteLine code throughout so I can see what's being called and where it's getting stuck.
Thanks.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Judah Himango wrote: The lblLoadingCase is a label? If so, don't update that in DoWork
I'd say this was my whole problem. No error was raised, but I changed this and now it's all working oh so sweetly. Thanks for pointing out what should have been obvious )
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|