|
Good luck in that and thanks for pointing out this, will save me some head scratching in the future.
|
|
|
|
|
hi all, i made this code to make multithreads for one method and every thread take one packet to move but it didnot work, Is there any error in this code
private void btn_simulate_Click(object sender, EventArgs e)<br />
{<br />
for (int i = 0; i < lineArray.LineList.Count; i++)<br />
{<br />
packetsMovingThreadArray.Add(new Thread(threadProcedure));<br />
dataPacketsArray.Add(new Packet());<br />
}<br />
this.btn_simulate.Enabled = false;<br />
this.btn_stop.Enabled = true;<br />
movingPacketThreadFlag = true;<br />
for (int i = 0; i < lineArray.LineList.Count; i++)<br />
{<br />
((Thread)packetsMovingThreadArray[i]).Start();<br />
}<br />
}<br />
int simulationIndex = -1;<br />
private void threadProcedure()<br />
{<br />
simulationIndex++;<br />
Packet pack = ((Packet)dataPacketsArray[simulationIndex]);<br />
AdHocMobility.simulate(ref pack,((Line)lineArray.LineList[simulationIndex]),<br />
this);<br />
}<br />
private void btn_stop_Click(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
this.btn_stop.Enabled = false;<br />
this.btn_simulate.Enabled = true;<br />
packetsMovingThreadArray.Clear();<br />
foreach (Thread Th in packetsMovingThreadArray )<br />
{<br />
Th.Abort(); <br />
}<br />
simulationIndex = -1;<br />
movingPacketThreadFlag = false;<br />
Invalidate();<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message);<br />
}<br />
}
thanks
Generator
|
|
|
|
|
HexaDeveloper wrote: Is there any error in this code
If "simulate()" is painting you can't do that from a worker thread
and
the way you are using simulationIndex does not look safe
in short you need to do some more reading on multi-thread concepts like synchronization. I recommend books by Jeffery Richter on that subject.
|
|
|
|
|
led mike wrote: If "simulate()" is painting you can't do that from a worker thread
hi can u explain this statement ,
in simulate i called movePacket() and this method returns
new points for the packet and i draw it in onPaint()
and actually i want to ask what is the meaning of not safe to use simulationIndex
thanx
Generator
|
|
|
|
|
Multi-Threaded application almost always need one or more forms of "Syncrhonization[^]"
It's not something that can be explained in a few sentences in a forum message. Look at the link and the author [^]I suggested.
|
|
|
|
|
use System.Threading.ThreadStart delegate instead of Thread
|
|
|
|
|
Hi,
This is hard to explain, but it is a simple enough problem...
I have a large dataset (Class 'Dataset') that will be altered by a sequence of events (Abstract class Event, not events in the sense of delegate events). I need to be able to reconstruct the state of this dataset after any amount of events, so I designed an Event abstract class which will be extended for every type of event that can happen. An instance of the specific type is created, applied to the dataset, and stored in a list whenever an event occurs.
Now, it is quite important that the rest of my program does not modify any of the data without constructing an Event, otherwise if I recreate the dataset at that point in time (by re-applying all the events in my list) it will not be consistent with the original.
At the moment my Event has the abstract method Apply(Dataset data), which applies the changes for that event to the given dataset. However, this means I have to keep a most of Dataset's members public, and (besides being bad OO practice) if I or someone else accidentally modify any of them w/o an Event, it's going to be quite hard to debug.
My other option would be to include an overloaded method in Dataset that applies each Event accordingly, but I'm not sure how it will apply. For example, if I have extended Event to EventA, and do:
<br />
Event e = new EventA();<br />
<br />
Dataset.ApplyEvent (e);<br />
and Dataset has two ApplyEvent methods:
<br />
public void ApplyEvent (Event e) {}<br />
<br />
public void ApplyEvent (EventA e) {}<br />
Will the overloaded method for EventA be called? Or is there a simpler, elegant solution I'm not thinking of?
Sorry for the long post and thanks for your help
|
|
|
|
|
ruanr wrote: I need to be able to reconstruct the state of this dataset after any amount of events
Are you talking about an "Undo" operation? If so please refer to the "Command Pattern[^]"
|
|
|
|
|
That as well, but eventually I will need to export all the events to disk, and be able to reapply them to get the state of the set at any time during initial operation..
But thanks for the link, it is helpful
|
|
|
|
|
ruanr wrote: I will need to export all the events to disk, and be able to reapply them to get the state of the set
"the state of the set" ? Do you mean the DataSet? This is very confusing, if your end goal is to get a DataSet to some previous state, you just serialize the DataSet (like as XML) when that state is arrived at, and then when you want to get back to that you would just load a DataSet from the XML.
|
|
|
|
|
Hi,
I have a problem I need to solve it quite fast: I need to write a function that have as input an URL, and return an number, the Google Page Rank for that page (like page rank that Google toolbar give)
Is someone here that know how to do this? I need to write this function in c# (to integrate in an existing application). Or an site to read how to do it!
|
|
|
|
|
|
All this "Page Rank Calculators" uses an algorithm to get the number representing the Rank. I need that algorithm. 2 years ago I wrote an php script that do this, but I lost the code, and I cannot find it (for now).
I posted here this question with the hope that someone have that algorithm (can be c# or php code).
|
|
|
|
|
Hi,
I'm developing one windows appln with C#. I'm getting the error msg as " An unhandled exception of Type 'System.StackOverflowException' occurred in mscorlib.dll" . Control stops at the place where I declared the hashtable as:
public class Logger : IDisposable
{
Hashtable htMsgCount;
}
public Logger()
{
htMsgCount = new Hashtable();
}
Control comes and stay at htMsgCount. What could be the problem. The funny thing is it was working fine just I made a few changes in my code. After compiling and tried to run, it is giving me this error. Anybody who knows please help me.
Thanks in advance.
Meeram395
|
|
|
|
|
The problem is elsewhere in the call stack
|
|
|
|
|
Hi,
I don't understand what you mean. Can you please clarify a little bit.
Meeram395
|
|
|
|
|
Standard question #5:
No, that is not the code you are using. It can't produce that result. What does the code you are using look like?
The constructor of the class has to be inside the class, so the code that you have shown doesn't even compile. It's hard to tell what's wrong with a piece of code, when you are not even looking at the code that is actually used.
Post the actual code that you are using, or a complete example that reproduces the error.
---
single minded; short sighted; long gone;
|
|
|
|
|
HI,
Thanks for the reply. The constructor is within the class only. I have put the closing braces wrongly before the constructor. Sorry for that.
-- modified at 1:44 Tuesday 26th June, 2007
Meeram395
|
|
|
|
|
I'm guessing here: if Hashtable is a class of your own, and its constructor needs
a new Logger, then thatwill need a new Hashtable which needs a new logger etc. until
the stack fills.
|
|
|
|
|
Dears,
Post your articles here too
www.exposecode.com
Mussarat Aziz
|
|
|
|
|
Your post has been reported as spam, and will be treated as such.
|
|
|
|
|
|
Yeah, I tagged that one too, but as I look back at that article, his post has disappeared.
Either way, advertising "Post your articles on MY site!" just doesn't deserve a warm and fuzzy reception around here.
|
|
|
|
|
My code connects to an Access database (SC226_db.mdb), which is installed in the application folder, using the code:
OleDbConnection Connection1 = new OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=SC226_db.mdb");
Connection1.Open();
This works fine until a FileOpen dialog is used to access a file in another folder, then my app looks for the database file in this other folder. Can anyone please tel me how to ensure that my app always looks for the database in the application folder?
|
|
|
|
|
There is a setting on the FileDialog to keep or move the current directory. I don't recall exactly what the property is off the top of my head, but it will be in MSDN or you might be able to guess from the intellisense.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
* Reading: Developer Day 5
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|