|
Thanks for the tip, however, I am looking for something more real-time, how can I approach this?
|
|
|
|
|
Set up a timer, with the appropriate interval, and put a panel or similar on your form.
When the timer tick event fires, use Panel.Invalidate to force a re-draw.
Override the Panel.Paint event and draw your graph. You may wish to set DoubleBuffered to avoid flicker.You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
|
|
|
|
|
Hello all,
Does anybody know how can I add text to an elliptic line using GDI ?
Thanks,
Berlus
|
|
|
|
|
See here[^]
It's using Bezier, but you can change that bit quite easily.You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
I have one main thread, and many other background thread.
The main usage of those background thread is to query data (quite a number of queries from the web, that's why I make it threads: avoid the lagging of the user interface ).
When it comes to exporting the data in the main thread(the user interface), I need to wait until all the other thread finished.
in my code, I use:
while (QueryThread.threadCount != 0)
{
Thread.CurrentThread.Join(1000);
Console.WriteLine(QueryThread.threadCount);
}
if I comment the while loop out, the program run smoothly, but some of my exported data will have possibility of showing some "unwanted" material since some of the background threads hasn't finished their work.
however, the above while loop is infinite, the threadCount never change, which means during the "Join()" method, no background thread is being ran.
why the background threads are not ran and how can i solve this problem?
Thanks a lot!
|
|
|
|
|
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?
|
|
|
|