|
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
|
|
|
|
|
|
Hi,
you as an old CPian should know better on how to format your posts .
Christian Graus wrote: // Without this, the progress bar never showed at all.
Application.DoEvents();
This tells me that your GUI thread is definitely doing a lot of work. What I'm missing in your code is on how you start the processing. It should be something like threadLoadCase.RunWorkerAsync() . Also I do not quite get to which method you refer to with and the guts of the method:. Do you mean LoadCase ? If not then where is this code called?
Robert
|
|
|
|
|
if (RequestIDs.Count < 5 && !threadGetRequests.IsBusy)
{
threadGetRequests.RunWorkerAsync();
}
This happens inside a button click. If RequestIDs > 5 then we don't need to go looking for more, we can just load one. That's the other thread, actually, but they both work the same sort of way.
if (timerLoadCases == null || !timerLoadCases.Enabled)
{
timerLoadCases = new System.Windows.Forms.Timer();
timerLoadCases.Interval = 5000;
timerLoadCases.Tick += delegate
{
if (RequestIDs.Count > 0 && !threadLoadCase.IsBusy)
{
threadLoadCase.RunWorkerAsync(RequestIDs[0]);
RequestIDs.RemoveAt(0);
}
};
timerLoadCases.Start();
}
This is the other one, if we have a RequestID to download and there's none downloading now, we start downloading one. This adds them to a queue, we view from the queue.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello,
After a long hours of search in google, I wasn't able to find what I was looking for. I need pointers on how to write an application that will let me manage network bandwidth throttling. I want to run a local cable network and instead of relying on a 3rd party software, I want to write on for the sake of learning something new. It surely sounds challenging but I didn't thought it would be that challenging, at beginning.
Anyways, I want to limit bytes / sec on a certain IP with ports range etc. Maybe few guides in the right direction please?
Any help will be appreciated.
Thanks
|
|
|
|
|
Very big job. You basically have to write a proxy service that takes in requests on one side, makes the outward connection to the requested address on the other side and then passes the data between the two connections at the throttle rate you configured.
Not REALLY difficult, but very difficult to do well. Covers lots of different areas (threading, sockets, streams, etc...)
While I admire your want to learn this, you might want to settle down a bit and pick PARTS of this problem and learn each one very well first.
|
|
|
|
|
Thanks for replying, Ray. Actually, I want to do it like SoftPerfect's Bandwidth Manager or NetLimiter, i.e. without using a proxy.
I do have some fair knowledge of threading, streams and basic knowledge of sockets but I am willing to spend much time to improve on these areas. There's no haste and I have lots of time on hands to learn all the required stuff. The bottomline is, I just want to do it whether I convert it to a full-blown software or not.
Basically, I am looking for guides on how network bandwidth limiting can be done on windows using C# .NET or maybe just generally. For a start, I will probably be testing it on my home network by limiting speed on all ports on my desktop PC.
Thanks for help.
|
|
|
|
|
it is a difficult thing to do. I think what you are trying to write is what's called a "traffic shaper". you will probably need some kind of a low level proxy, through which all data packets will go through, so that you can control the rate in which these packets are passed over the network.
This proxy would have to use something like the winpcap library (or libpcap if you're not working on windows).
anyway, good places to start are: this article[^], which uses raw sockets to handle packets, and this one[^], which ports winpcap to c#
there are no facts, only interpretations
|
|
|
|
|
Hi , did u find the way? i really need it!
|
|
|
|
|
Well with how well HttpWebRequest worked reading a file, i though FTP would be just a s easy, not quite so, i have:
FtpWebRequest request =(FtpWebRequest)WebRequest.Create(@"ftp://address/1.txt");<br />
request.Credentials = new NetworkCredential("username", "password");<br />
request.Method = WebRequestMethods.Ftp.AppendFile;<br />
Stream FS = request.GetRequestStream();<br />
StreamReader SR = new StreamReader(FS, true);<br />
string line = SR.ReadLine();
I imagined that that would read the file, i was wrong, says that the stream is not readable.
So apart from the not being able to read the file, i need to be able to edit the file, and there would be the possibility of multiple people trying to edit it at the same time, how would i do this?
(No two people would be editing the same line in the file, if that makes any difference at all)
So err, any help or suggestions would be great
|
|
|
|
|