Click here to Skip to main content
15,892,059 members
Home / Discussions / C#
   

C#

 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
User 680178016-Feb-10 9:08
User 680178016-Feb-10 9:08 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
Daniel Grunwald16-Feb-10 9:39
Daniel Grunwald16-Feb-10 9:39 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
Luc Pattyn16-Feb-10 9:45
sitebuilderLuc Pattyn16-Feb-10 9:45 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
User 680178016-Feb-10 10:02
User 680178016-Feb-10 10:02 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
User 680178016-Feb-10 10:09
User 680178016-Feb-10 10:09 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
User 680178017-Feb-10 7:05
User 680178017-Feb-10 7:05 
AnswerRe: Cross-Threading problem, InvokeRequired and Events Pin
#realJSOP15-Feb-10 23:21
mve#realJSOP15-Feb-10 23:21 
GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
User 680178019-Feb-10 4:10
User 680178019-Feb-10 4:10 
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(); //displaying information for visual guiding
        Options(); //options for training
        /*
        this.tbVeryBig.AppendText("[" + DateTime.Now.TimeOfDay.ToString() + "]: INPUT NEURONS [" + inputNeurons + "]\r\n");
        this.tbVeryBig.AppendText("[" + DateTime.Now.TimeOfDay.ToString() + "]: HIDEEN NEURONS [" + hiddenNeurons + "]\r\n");
        this.tbVeryBig.AppendText("[" + DateTime.Now.TimeOfDay.ToString() + "]: OUTPUT NEURONS [" + outputNeurons + "]\r\n");
        this.tbVeryBig.AppendText("[" + DateTime.Now.TimeOfDay.ToString() + "]: ERROR RATE [" + errorTreshold + "]\r\n");
        this.tbVeryBig.AppendText("[" + DateTime.Now.TimeOfDay.ToString() + "]: LEARNING RATE [" + learningRate + "]\r\n");
        this.tbVeryBig.AppendText("[" + DateTime.Now.TimeOfDay.ToString() + "]: PROGRESS FILTER [" + filtername + "]\r\n");
        */
        //instanciate training class
        trainingANN_instance = new ANN_Training();
        Invoke(guiUpdateDuringLearning);



        //trainingANN_instance.LoopEnd += new LoopEndHandler(trainingANN_instance_LoopEnd);
        trainingANN_instance.GoodFactsSynch += new StatsSynch(trainingANN_instance_GoodFactsSynch); //updates textbox of good facts
        trainingANN_instance.BadFactsSynch += new StatsSynch(trainingANN_instance_BadFactsSynch); //updates tbox of bad
        trainingANN_instance.RatioSynch += new StatsSynch(trainingANN_instance_RatioSynch); //updates tbox ratio
        trainingANN_instance.ConvergeRateSynch += new StatsSynch(trainingANN_instance_ConvergeRateSynch); //converge
        trainingANN_instance.EpochSynch += new StatsSynch(trainingANN_instance_EpochSynch);//epoch
        trainingANN_instance.LogReportSynch += new StringSynch(trainingANN_instance_LogReportSynch); //log reporter
        trainingANN_instance.BadFactsForGraphSynch += new StatsSynch(trainingANN_instance_BadFactsForGraphSynch); //graph
        //trainingANN_instance.WHMatrixSynch += new Weights_MatrixSynch(trainingANN_instance_WHMatrixSynch);
        //trainingANN_instance.WOMatrixSynch += new Weights_MatrixSynch(trainingANN_instance_WOMatrixSynch);

        //training ANN
        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.

GeneralRe: Cross-Threading problem, InvokeRequired and Events Pin
User 680178019-Feb-10 8:06
User 680178019-Feb-10 8:06 
QuestionC# TableLayoutPanel MouseLeave Pin
ikurtz15-Feb-10 5:27
ikurtz15-Feb-10 5:27 
AnswerRe: C# TableLayoutPanel MouseLeave Pin
AhsanS15-Feb-10 5:48
AhsanS15-Feb-10 5:48 
GeneralRe: C# TableLayoutPanel MouseLeave Pin
ikurtz15-Feb-10 6:21
ikurtz15-Feb-10 6:21 
QuestionProblem using a class Pin
msg5512115-Feb-10 4:59
msg5512115-Feb-10 4:59 
AnswerRe: Problem using a class Pin
vaghelabhavesh15-Feb-10 5:04
vaghelabhavesh15-Feb-10 5:04 
GeneralRe: Problem using a class Pin
msg5512115-Feb-10 5:31
msg5512115-Feb-10 5:31 
GeneralRe: Problem using a class Pin
vaghelabhavesh15-Feb-10 5:53
vaghelabhavesh15-Feb-10 5:53 
QuestionIP Address Pin
sanforjackass15-Feb-10 4:16
sanforjackass15-Feb-10 4:16 
AnswerRe: IP Address Pin
Migounette15-Feb-10 4:18
Migounette15-Feb-10 4:18 
GeneralRe: IP Address Pin
sanforjackass15-Feb-10 4:43
sanforjackass15-Feb-10 4:43 
GeneralRe: IP Address Pin
Dave Kreskowiak15-Feb-10 5:46
mveDave Kreskowiak15-Feb-10 5:46 
AnswerRe: IP Address Pin
Som Shekhar15-Feb-10 5:55
Som Shekhar15-Feb-10 5:55 
GeneralRe: IP Address Pin
sanforjackass15-Feb-10 9:20
sanforjackass15-Feb-10 9:20 
GeneralRe: IP Address Pin
Som Shekhar15-Feb-10 18:04
Som Shekhar15-Feb-10 18:04 
GeneralRe: IP Address Pin
sanforjackass15-Feb-10 21:37
sanforjackass15-Feb-10 21:37 
GeneralRe: IP Address Pin
Som Shekhar15-Feb-10 21:39
Som Shekhar15-Feb-10 21:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.