|
Have you tried to call Join() on your separate working threads in your main thread instead?
For instance in your main thread
Thread t1 = new Thread(DoWork_1);
Thread t2 = new Thread(DoWork_2);
Thread t3 = new Thread(DoWork_3);
t1.Start();
t2.Start();
t3.Start();
t1.Join();
t2.Join();
t3.Join();
Console.WriteLine("All threads done");
|
|
|
|
|
|
You are using background threads to keep the UI responsive, which is good. But then you are blocking in this method. I suggest you disable exporting in your UI until you know all the data is ready.
You will still have to detect when your background threads have completed and the data is ready to be exported, which is a similar requirement to the code you posted. So you will still have to get the threads to signal they have completed. Setting an int counter to the number of threads and having them decrement it when they complete is as good a solution as any. You will also have to invoke a method on your UI thread when all the threads have completed, which would re-enable your export functionality.
You need to find out why QueryThread.threadCount is not being decremented. The code you posted will not stop background threads from running, so you have another problem somewhere.
One possibility is that you have not declared threadCount as volatile . Does the code work in a Debug build ( without optimizations ) ?
Nick----------------------------------
Be excellent to each other
|
|
|
|
|
HideIvy wrote: Thread.CurrentThread.Join(1000);
Why did you write this?
|
|
|
|
|
|
Thanks all.
I am not clear enough about threads before.
I changed my implementation to a Producer-Consumer model now.
And things go well =]
|
|
|
|
|
main forum:
private void Filter_combo_SelectedIndexChanged(object sender, EventArgs e)
{
string filter = Filter_combo.Text;
using (var db = new mombooksDataContext(Properties.Settings.Default.BooksConnectionString2))
{
NodeBuilder.BuildNodes(treeView1.Nodes,db.Authors, db.Books, filter);
treeView1.Nodes.Clear();
}
}
class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using momdb;
namespace Utilties
{
public sealed class NodeBuilder
{
public static void BuildNodes(TreeNodeCollection nodes,IEnumerable<Author>authors, IEnumerable<Book> books, string filter)
{
if (filter == "Keywords" || filter == "Title")
{
books.ToList().ForEach(m =>
{
TreeNode node = new TreeNode(filter);
node.Tag = m;
nodes.Add(node);
});
}
if (filter =="Author")
{
authors.ToList().ForEach(m =>
{
TreeNode node =new TreeNode(filter);
node.Tag=m;
nodes.Add(node);
});
}
}
}
whenever i do this I never get any results to my treeview and I can't really comprehend why not. I'm passing it the nodes and I would think it would populate the tree from those nodes modified on Friday, February 19, 2010 11:00 PM
|
|
|
|
|
try replacing
NodeBuilder.BuildNodes(treeView1.Nodes,db.Authors, db.Books, filter); treeView1.Nodes.Clear();
with:
TreeNodeCollection[] nodes = new TreeNodeCollection[treeView1.Nodes.Count];
treeView1.Nodes.CopyTo(nodes, 0);
treeView1.Nodes.Clear();
treeView1.Nodes.AddRange(NodeBuilder.BuildNodes(nodes, db.Authors, db.Books, filter));
and modify your BuildNodes method to return an array of TreeNode.
|
|
|
|
|
okay i been battling this for hours. I tried taking and returning a treenode[]
but i keep getting can't convert type treenode to treenode[]?
any chance of a little more insight on this please ?modified on Friday, February 19, 2010 11:00 PM
|
|
|
|
|
here is what I have
private void Filter_combo_SelectedIndexChanged(object sender, EventArgs e)
{
string filter = Filter_combo.Text;
using (var db = new mombooksDataContext(Properties.Settings.Default.BooksConnectionString2))
{
TreeNodeCollection[] nodes = new TreeNodeCollection[treeView1.Nodes.Count];
treeView1.Nodes.CopyTo(nodes, 0);
treeView1.Nodes.Clear();
treeView1.Nodes.AddRange(NodeBuilder.BuildNodes(nodes, db.Authors, db.Books, filter));
}
}
class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using momdb;
namespace Utilties
{
public sealed class NodeBuilder
{
public static TreeNode[] BuildNodes(TreeNodeCollection nodes,IEnumerable<Author>authors, IEnumerable<Book> books, string filter)
{
TreeNode[] holder;
if (filter == "Keywords" || filter == "Title")
{
filter = string.Format("m.{0}", filter);
books.ToList().ForEach(m =>
{
TreeNode node = new TreeNode(filter);
node.Tag = m;
nodes.Add(node);
});
}
if (filter =="Author")
{
authors.ToList().ForEach(m =>
{
TreeNode node =new TreeNode(filter);
node.Tag=m;
nodes.Add(node);
});
}
return holder = new TreeNode[nodes.Count];
}
}
}
|
|
|
|
|
tonyonlinux wrote: return holder = new TreeNode[nodes.Count];
this line returns an empty array of Lenght nodes.Count.
use something like
holder = new TreeNode[nodes.Count];
holder.AddRange(nodes);
return holder;
|
|
|
|
|
there doesn't appear to be an addrange associate with holder.
would it perhaps be another method I have to call ?
|
|
|
|
|
yep.
just use a for(int i=0;i
|
|
|
|
|
here is what I've come up with so far. 208 nodes get put into the array i checked that in the debugger but i get an exception each time it finds a instance where the node is the same. in example
says can not add or insert the item 'tbone,eater' in more than one place.
here is what i'm using in my main form
private void Filter_combo_SelectedIndexChanged(object sender, EventArgs e)
{
string filter = Filter_combo.Text;
using (var db = new mombooksDataContext(Properties.Settings.Default.BooksConnectionString2))
{
TreeNodeCollection[] nodes = new TreeNodeCollection[treeView1.Nodes.Count];
treeView1.Nodes.CopyTo(nodes, 0);
treeView1.Nodes.Clear();
treeView1.Nodes.AddRange(NodeBuilder.BuildNodes(treeView1.Nodes, db.Authors, db.Books, filter));
}
}
then i'm calling the modified class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using momdb;
namespace Utilties
{
public sealed class NodeBuilder
{
public static TreeNode[] BuildNodes(TreeNodeCollection nodes,IEnumerable<Author>authors,IEnumerable<Book>books,string filter)
{
TreeNode node = new TreeNode();
if (filter == "Keywords")
{
node = nodes.Add("Keywords");
books.ToList().ForEach(m =>
{
node.Nodes.Add(m.Keywords);
node.Tag = filter;
});
}
if (filter == "Title")
{
node = nodes.Add("Title");
books.ToList().ForEach(m =>
{
node.Nodes.Add(m.Title);
node.Tag = filter;
});
}
if (filter =="Author")
{
node = nodes.Add("Authors");
authors = authors.ToList().Distinct();
authors.ToList().ForEach(m =>
{
node.Nodes.Add(string.Format("{0},{1}",m.AuthorFirst,m.AuthorLast));
node.Tag=filter;
});
}
TreeNode[] holder = new TreeNode[node.Nodes.Count];
for (int i = 0; i < node.Nodes.Count; i++)
{
holder[i] = node.Nodes[i];
}
return holder;
}
}
}
still confused
|
|
|
|
|
I don't know exactly and right know I don't have the time to try it and see what is wrong.
I mean the message is clear => something with duplicate items.
You could try to return the Tree nodes collection and of course edit the method to return a Collection
not array. See if it helps
|
|
|
|
|
I figured it out thanks for your time...
|
|
|
|
|
i have two collections defined below
List<ScienceStudents> lstScienceStudents = GetScienceStudentCollection();
List<MathsStudents> lstMathsStudents = GetMathsStudentCollection();
Now both the classes ScienceStudents and MathsStudents have a common id Student_Id.
I need to set the boolean property IsMathStudent in lstScienceStudents to true by joining the two collection.
To be more clear here is the code
for (int i = 0; i < lstScienceStudents .Count; i++)
{
for (int j = 0; j < lstMathsStudents.Count; j++)
{
if (lstScienceStudents[i].Student_Id == lstMathsStudents[j].Student_Id)
lstScienceStudents[i].IsMathStudent = true;
}
}
I know i can get the collection of MathsStudents in ScienceStudent collection using join in linq. But i need to set the flag to true in the lstScienceStudent collection list.
How can i do it?
|
|
|
|
|
You can't modify a field during a Linq query. But, you can return a new IEnuerable(T) or List(T)
Something like this:
var needed = from sRec in lstScienceStudents
from mRec in lstMathsStudents
where sRec.Student_Id.Equals(mRec.Student_Id)
select new{
Field1here = YouKnowWhat;
Field2here = YouKnowWhat;
}
|
|
|
|
|
Hi everyone,
I have a minor problem with one of my assignments. I want my child form to show defalut values on open. When i update the data or change the existing data i want it to be saved and then when i reopen the form i want those values to be shown. To elaborate more, I have a parent form and child form. When i select an item from a combo box in parent form and click on update button, the child form opens and shows default values. And then when i change the default values and click the update button in the child form the values need to be changed. So when i close the child form and reselect the same product and click update from parent form. The new values need to be shown. I am attaching a link to my code. Please take a look
http://nexusfactor.webs.com/LabAssignment3.rar
|
|
|
|
|
Nobody is going to download your code. You can paste your code here (at least, the relevant bits). What is your question? What are you having a problem with?
Pass the values into the child form via the constructor. Return the result when the child form closes by storing them to a public property of the child form. The parent form can then access that property after the child form closes and save that value for later (e.g., when passing it again to the constructor of the child form).
Is that the answer you were looking for, or did you have a more specific problem?
|
|
|
|
|
in my parent form i created an array string with values. i passed that array to the child form's constructor. then i created instance array in the child form and i set that equal to the array passed from the constructor so i can use it. i used it to display the passed string value in my combo box. i also created a public string variable. then on button click i set the public string variable equal to the newly selected item from combo box. i go back to my parent form and my code looks something like this:
private void updateProductInfo_Click(object sender, EventArgs e)
{
productStatus = false;
ProductForm pFTwo = new ProductForm(this, category);
pFTwo.Show();
if (pFTwo.updateStatus == true)
{
category[pFTwo.aProductCategoryIndex] = pFTwo.aProductCategory;
}
}
as u can see my public variables from my child form is "aProductCategory". but nothing is happening when i reopen my child form. the combo box value is still the same
|
|
|
|
|
You are using a local variable for your ProductForm so every time you go through the updateProductInfo_Click() method you start a new form. Create your child form in your main form intialisation and use that throughout your code.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
|
Set the data how you would like in your child's form load event.
|
|
|
|
|