|
Hey, guys. I think i managed to sovle, but I've got few questions.
My solution:
private void Initiate_ANN_Training()
{
MethodInvoker guiUpdateDuringLearning = new MethodInvoker(ThreadDynamic);
MethodInvoker guiUpdateAfterLearning = new MethodInvoker(AfterLearning);
SettingsInfoDisplay();
Options();
trainingANN_instance = new ANN_Training();
Invoke(guiUpdateDuringLearning);
trainingANN_instance.GoodFactsSynch += new StatsSynch(trainingANN_instance_GoodFactsSynch);
trainingANN_instance.BadFactsSynch += new StatsSynch(trainingANN_instance_BadFactsSynch);
trainingANN_instance.RatioSynch += new StatsSynch(trainingANN_instance_RatioSynch);
trainingANN_instance.ConvergeRateSynch += new StatsSynch(trainingANN_instance_ConvergeRateSynch);
trainingANN_instance.EpochSynch += new StatsSynch(trainingANN_instance_EpochSynch);
trainingANN_instance.LogReportSynch += new StringSynch(trainingANN_instance_LogReportSynch);
trainingANN_instance.BadFactsForGraphSynch += new StatsSynch(trainingANN_instance_BadFactsForGraphSynch);
trainingANN_instance.Training(inputNeurons, hiddenNeurons, outputNeurons, errorTreshold, learningRate, progressFilter, logOption);
Invoke(guiUpdateAfterLearning);
}
For events methods:
private void trainingANN_instance_RatioSynch(double variable)
{
if (this.InvokeRequired)
{
BeginInvoke(new DelegateToCrossThread_Double(trainingANN_instance_RatioSynch), new object[] { variable });
return;
}
else
{
this.tbRatio.Text = "" + variable;
}
}
Question 1: BeginInvoke invokes asynch. What does it mean? If thread works on variable X and its current value 5, would it reflect value 5 or something else? My goal is to show real-time current information. Does BeginInvoke compromise this issue?
Question 2: What are other solutions to my "problem"? Would like to know alternative ways.
Question 3: At some point, if I leave my code as it was, except Initiate_ANN_Learning method, removing InvokeRequired from it, I get this error:
System.Reflection.TargetParameterCountException was unhandled
Message="Parameter count mismatch."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at ANN_Project.ANN_GUI.trainingANN_instance_RatioSynch(Double variable) in C:\Users\EARNEST\Documents\Visual Studio 2008\Projects\ANN_take2\ANN_take2\ANN_GUI.cs:line 541
at ANN_Project.ANN_Training.Training(Int32 inputNeurons, Int32 hiddenNeurons, Int32 outputNeurons, Double errorThreshold, Double learning, Int32 optionSel, Boolean dynamicLogOption) in C:\Users\EARNEST\Documents\Visual Studio 2008\Projects\ANN_take2\ANN_take2\ANN_Training.cs:line 255
at ANN_Project.ANN_GUI.Initiate_ANN_Training() in C:\Users\EARNEST\Documents\Visual Studio 2008\Projects\ANN_take2\ANN_take2\ANN_GUI.cs:line 368
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
in my old
private void trainingANN_instance_RatioSynch(double variable)
{
if (this.InvokeRequired)
{
DelegateToCrossThread_Double del = new DelegateToCrossThread_Double(trainingANN_instance_BadFactsForGraphSynch);
this.Invoke(del);
}
else
{
this.tbRatio.Text = "" + variable;
}
}
Can some1 explain it pls?
Final question: Can some1 explain pls why MethodInvoke , BeginInvoke solved the problem, while InvokeRequired approach was useless?
Appreciate your input and understanding!
modified 1-Aug-19 21:02pm.
|
|
|
|
|
I have some performance issues. If I start moving when the calculation thread is activated, the textbox updates can freeze or hang up and then "jump" to new values, let's say it stopped updating on 23, then it will not respond for a second, and then will jump to 59 or so. Also, sometimes my application acts as if there is no multithreading there Does not respond
modified 1-Aug-19 21:02pm.
|
|
|
|
|
greetings, i am developing a battleships clone game and i have an issue with TableLayoutPanel MouseLeave event.
first MouseMove:
private PictureBox HomeLastPicBox = new PictureBox();
private TableLayoutPanelCellPosition homeLastPosition = new TableLayoutPanelCellPosition(0, 0);
private void HomeTableLayoutPanel_MouseMove(object sender, MouseEventArgs e)
{
PictureBox NowPicControl = (PictureBox)(HomeTableLayoutPanel.GetChildAtPoint(e.Location));
if ((NowPicControl != null) && (NowPicControl != HomeLastPicBox))
{
HomeLastPicBox = (PictureBox)(HomeTableLayoutPanel.GetControlFromPosition(homeLastPosition.Column, homeLastPosition.Row));
if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
{
HomeLastPicBox.Image = Properties.Resources.water;
}
TableLayoutPanelCellPosition homeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(NowPicControl);
if (GameModel.HomeCellStatus(homeCurrentPosition.Column, homeCurrentPosition.Row) == Cell.cellState.WATER)
{
NowPicControl.Image = Properties.Resources.scan;
}
homeLastPosition = homeCurrentPosition;
}
}
this appears to function properly.
now the MouseLeave event:
private void HomeTableLayoutPanel_MouseLeave(object sender, EventArgs e)
{
MessageBox.Show("col " + homeLastPosition.Column.ToString() + " row " + homeLastPosition.Row.ToString());
if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
{
HomeLastPicBox.Image = Properties.Resources.water;
MessageBox.Show("hi");
}
HomeLastPicBox = new PictureBox();
}
this is acting strange. it goes through the code and even a "HI" is displayed but the PictureBox image is not changed to water. any ideas as to why? this does not happen all the time, only from time to time.
what the above code is doing is basically scanning through the table cells and if the cell content is WATER then it updates the table cell image to SCAN and as the user moves onwards it is switching the cell image back to WATER.
hope this is enough information. please ask if more is needed.
thank you in advance.
|
|
|
|
|
<pre>
if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
{
HomeLastPicBox.Image = Properties.Resources.water;
MessageBox.Show("hi");
}
</pre>
i wonder why are you using this
<pre>HomeLastPicBox = new PictureBox();</pre>
when you have already assigned the picture to this picture box in the if block. after displaying the message box you need to return.
do it like this.
<pre>
if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
{
HomeLastPicBox.Image = Properties.Resources.water;
MessageBox.Show("hi");
return;
}
hope it helps.
</pre>
Ahsan Ullah
Senior Software Engineer
MCTS 2.0
|
|
|
|
|
no thats not going to work. i have made some progress. the reason im experiencing this behaviour is because mousemove is being called after the call of mouseleave.
|
|
|
|
|
I have created a C# application that has 3 modules so far, default.aspx, registration.aspx and supplierinfo.aspx all using code_behind. I then created a class dbConnect.cs that I will use to connect to a DB. I am able to instatiate the dbConnect class in supplierinfo.aspx.cs and get the connection string. In the other 2 modules I am unable to instatiate the dbConnect class. I enter:
var dbCon = new dbConnect(); OR dbConnect dbCon = new dbConnect;
and then do a build. I am getting the following error:
Error 35 The type or namespace name 'dbConnect' could not be found (are you missing a using directive or an assembly reference?)
I can't see any differences in the modules that would cause this. Has anyone run into this before or have any suggestions what to look for?
Thanks for the help
|
|
|
|
|
So what you are saying is - all four classes belongs to the same namespace and you are still getting this error? Interesting.
I am thinking you may be missing a "using" statement.If you fail to plan, you plan to fail!
Books are as useful to a stupid person as a mirror is useful to a blind person. - Chanakya
|
|
|
|
|
Sometimes when we have a problem we fail to look at the obvious. We tend to look for the complex solution and not the simple solution. Turns out the problem is that 2 of the modules were not using the namespace.
Thanks for the help.
|
|
|
|
|
msg55121 wrote: Thanks for the help.
you are welcome If you fail to plan, you plan to fail!
Books are as useful to a stupid person as a mirror is useful to a blind person. - Chanakya
|
|
|
|
|
I have 256/DSL connection with non static IP and i have router to let me surf the net.
every time I connect to the internet I have Different IP.
is there a program to get this IP every time I connect.
|
|
|
|
|
Several options:
Stun / UPnP / Telenet acces to your box....
|
|
|
|
|
what do you mean??
can you be more clear
|
|
|
|
|
You'd have to ask the router what the IP address is. How you do that depends entirely on the router and the interfaces it provides that your code can talk to.
|
|
|
|
|
|
thanks
but as i said before i dont have a static IP but i think every time i connect to net i should have IP address and if i disconnect and reconnect i think i got another IP address so how can i get this address every time
|
|
|
|
|
Always read before you reply:
sanforjackass wrote: but as i said before i dont have a static IP
Yes. This is called Dynamic IP system. It happens because your ISP keeps a number of IP addresses reserved with it. Since at any point of time, all users are not connected, same IPs are being allocated to different people.
Som wrote:
You need to ask your ISP to provide you with a static IP address. Depending on your plan, it may be a free or paid service.
To have the same IP address everytime, you need to have a Static IP (same IP everytime). Speak to the customer service of your ISP and request for a static IP. I repeat. it can be a paid service.
|
|
|
|
|
do you really read my last reply!!
i know there is a different IP every time and I dont want to make it static from my ISP I just want to know the IP every time.
|
|
|
|
|
|
|
sanforjackass wrote: have you tried
Why would I give you a link without knowing what it is? This is a website you can visit to see your ip everytime you connect to internet.
|
|
|
|
|
|
|
have you tried
every time I open these pages at the same time each one give me different IP so what is the real IP
|
|
|
|
|
sanforjackass wrote: every time I open these pages at the same time
clarify!!
|
|
|
|
|
thanks
but have you see www.spyber.com
modified on Tuesday, February 16, 2010 4:44 AM
|
|
|
|