|
If you want your UI thread to stay responsive, then you will have to put your loop in a separate thread.
----------------------------
Be excellent to each other
EasiReports[^] My free reporting component for WinForms.
|
|
|
|
|
This looks like a typical case which multitherading can play a role in. Here is my take and see if it makes sense.
When you click the "run" (which I call it) button, start a thread. Place the infinite loop in the thread function. This should guarantee that the form still responds to your click while the infinite loop is looping.
In order for your infinite loop to accept new selections made by the user, there should be some data exchange between the main thread and your looping thread. This has to be done through some thread synchronization mechanisms, say, critical section or mutex.
In short, multithreading is a good way to solve your problem.
Best,
Jun
|
|
|
|
|
thank you. I was leaning toward multithread. but im surprised because in vb5 (which is older) we don't need to worry about this kinda problem.
Donkaiser
|
|
|
|
|
donkaiser wrote: but im surprised because in vb5 (which is older) we don't need to worry about this kinda problem.
What? If VB5 didn't have this 'problem', then it's because the loop was being run on a different thread behind the scenes. It's not really a problem; if you think about it logically, it's a natural outcome: one thread is flooded with work, so it cannot be bothered to do other tasks such as repainting the control or responding to user input. Therefore, long running tasks should not be run on the UI thread if you want a responsive UI.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Goof around music jam with my brothers (with video)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Have you try putting Application.DoEvents() in the loop?
|
|
|
|
|
I have datagrid with a dataset set as the DataSource. I have added a X number of tables to the dataset, but when I view my datagrid it shows all the tables in the datagrid but I can only view the first table. The other tables don't show when I click or navigate onto them.
How do I get it to open or view the other tables?
<br />
DataSet dataset = new DataSet("Sms Report");<br />
dataset.Tables.Add(sendItemsTable);<br />
<br />
packagesTables = new DataTable[sendItemsTable.Rows.Count];<br />
for(int i = 0; i < distinctPackagesTable.Rows.Count; i++)<br />
{<br />
packagesTables[0] =
}<br />
<br />
if(packagesTables.Length > 0)<br />
dataset.Tables.AddRange(packagesTables);<br />
<br />
dataset.AcceptChanges();<br />
<br />
dataGrid.DataSource = dataset;<br />
dataGridStyle1.MappingName = dataGrid.DataMember;<br />
dataGrid.Expand(0);<br />
Leon v Wyk
|
|
|
|
|
I would like to automating Team Foundation Server to have a console app get the latest on a list of projects.
Does anyone have a link on achieving this task?
1 line of code equals many bugs. So don't write any!!
-- modified at 12:37 Tuesday 20th June, 2006
|
|
|
|
|
How can protect against reverse engineering and hacking in .Net?
obfescation and generic encription is not enough?
thanks
Yigal
|
|
|
|
|
Google: international patent
|
|
|
|
|
Hello I was wondering if in C# we have something equivalent to this timer loop:
'loop for .1 second
Duration! = Timer + 0.1
Do Until Timer > Duration!
Dummy = DoEvents()
Loop
Donkaiser
|
|
|
|
|
I don't know what behavior that produces in VB5, thankfully.
I imagine something like this might do:
System.Threading.Thread.Sleep(0);
That suspends the current thread to allow waiting threads to execute
System.Threading.Thread.Sleep(100);
That specifies a "minimum" of 100 milliseconds but it could be longer I believe.
If I get flamed for answering a VB question you owe me! Last modified: Tuesday, June 20, 2006 10:13:30 AM --
|
|
|
|
|
how to add dynamic control in C#.net and how to store dynamic textbox control value to the database.
|
|
|
|
|
|
Hi gurus!
How do I get values from a list view control. The view is set to details. I want to get the values from the list and dump them into variables. I have tried the "GetItemAt( x, y )" method and the "HitTest( x, y )" methods, but both give me the following error:
System.NullReferanceException: Object referance not set to an instance of an object"
I use the following code
for(int iNum = 0; iNum < list1.Items.Count; iNum++)
{
ListViewItem selection = list1.GetItemAt(0, iNum);
string str = selection.Text;
// And then I write the values to the database
}
Any help would be GREATLY appreciated!
Kind greetings!
Willem Le Roux
-- modified at 9:46 Tuesday 20th June, 2006
|
|
|
|
|
That error happens when something isn't initialized. Your best bet is to debug and step through the application and check the values of the list view before you call one of those. Also, potentially, you might not have initialized the list view itself.
|
|
|
|
|
GetItemAt is not throwing the exception, selection.Text is. GetItemAt expects client coordinates (i.e. where the mouse cursor is). Use list1.Items and list1.Items[x].SubItems to access the values.
Josh
|
|
|
|
|
Dude, you are my new-found HERO!
Thanx Josh! Exactly what I wanted
Willem Le Roux
-- modified at 5:02 Wednesday 21st June, 2006
|
|
|
|
|
hello, I`m using this code, but it return files in alphabetic order, I need to list those files in date modified order.
string winDir = "../katalogas";
try
{
string[] files = Directory.GetFiles(winDir);
foreach (string fileName in files)
{
//
//
}
}
catch (IOException ex)
{
MessageBox.Show("Klaida! Nerandamas formų katalogas." + ex.Message);
Close();
}
}
|
|
|
|
|
I believe that it doesn't return the files in any specific order at all. They just happen to be ordered alphabetically in the directory. Probably because you have moved the folder (as that creates a new folder and moves the files) or have run defrag (which sorts the files in the directories).
You need to get more information about the files than just the name. Use DirectoryInfo.GetFiles to get FileInfo-object for the files.
Make a Comparer for two FileInfo-objects that compares the property you want to sort on, and use that in the Array.Sort method.
---
b { font-weight: normal; }
|
|
|
|
|
hai all,in my application i enter the user details in to the database and other details in the form of word document(using html file field),when i delete the user, it delete only the user information from the database but i need to delete the respective word document also (when i delete the respective record from the database).is it possible...?..if so tell me how to do this....
Regards,
ayyp
-- modified at 8:48 Tuesday 20th June, 2006
|
|
|
|
|
Can anyone help solve the following problem
Create a console application that prints all possible combinations of the number from 1 - 9 that equals 10. IE 1+1+1+1+1+1+1+1+1+1=10 AND 1+1+1+1+1+1+1+1+2=10 etc..
rules that apply:
3 + 7 = 10 and 7 + 3 = 10... both is not allowed, only one of those sums are required.
how do you do it?
|
|
|
|
|
izakfick wrote: how do you do it?
I'd do my own homework
|
|
|
|
|
izakfick wrote: how do you do it?
By reading back over you notes from class, and refering to the course material you have been given.
ie/ do you own homework! Or at very least show us what you've tried and what specific problem you are having!
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
now ain;t that a friendly answer, just say so if you don;t know..
this is what i've got so far. hey I'm trying and this isn;t for class cupid.
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
int[] intArray = {1,2,3,4,5,6,7,8,9};
Calculate c = new Calculate();
for(int a = 1; a < intArray.Length; a++)
{
for(int b = 1; b < intArray.Length; b++)
{
string output = c.calc(a,b);
if(output!="")
{
Console.WriteLine(output);
}
}
}
string stop = "";
}
}
public class Calculate
{
public string calc(int x, int y)
{
int iTotal = 0;
string s_out = "";
while(iTotal < 10)
{
iTotal = iTotal + x + y;
s_out = s_out + x.ToString() + " + " + y.ToString() + " + ";
if(iTotal == 10)
{
s_out = s_out.Substring(0,s_out.LastIndexOf("+")-1) + " = " + iTotal.ToString();
}
}
if(iTotal>10)
{
s_out = "";
}
return s_out;
}
}
|
|
|
|
|
Well .. the solution is very simple ... I am sure J4amieChowever, show us that you tried something atleast.
Jedi
|
|
|
|