Home > Net >  How to keep a piece of code has been performed?
How to keep a piece of code has been performed?

Time:02-19

C # code to my feeling is executed only once, in a general way, the c # code is associated with the controls in the interface, the latter one click, the corresponding code is executed, but in many parts of the control will not click on all the time, and will only click once, then how to ensure that the associated code can get continuous run?

CodePudding user response:

What is "sustainable operation"? Infinite loop?

CodePudding user response:

1/f, reference The kei ℡ response:
what call "sustainable operation"? Infinite loop?


Receive the outside of the data that is to say, c #, but external data is dynamic, c # to constantly refresh

CodePudding user response:

See the questions before, should be written before the PLC to write code, now want to write a machine code, want to use c # write?
C # is the common language, and the thinking of PLC are not quite same, ready-made before the thinking of writing may be have a lot of problems
What you need is similar to a button, such as start reading data that a machine, but under a machine may have been writing the data, so reading is a process of continuous? If so, the idea should be read a background process to deal with, he is always in the execution, button just begins and ends with a background process control,

CodePudding user response:

Control event binding must only after control event trigger start executing code, if it's continued to receive external data, for example, a serial port communication or Socket communication, then you need to open a thread to continue to monitor, thread with the delegate invoke to update the front desk controls,

CodePudding user response:

reference HZTLTGG reply: 3/f
see questions before, should be written before the PLC to write code, now want to write a machine code, want to use c # write?
C # is the common language, and the thinking of PLC are not quite same, ready-made before the thinking of writing may be have a lot of problems
What you need is similar to a button, such as start reading data that a machine, but under a machine may have been writing the data, so reading is a process of continuous? If so, the idea should be read a background process to deal with, he is always in the execution, button just begins and ends with a background process control,


Is like this, can you tell me how to do?

CodePudding user response:

Look at the loop body

CodePudding user response:

Hope to run stably, can create a Windows service program,

CodePudding user response:

Really think impassability you didn't understand the basic concepts of the execution of a program logic, but where are work directly to fit the courage,

Your problem can analogy

You press the switch, the TV will continue to play, then you was just a switch button events, continue to play is a thread, so, you will need to continue to perform the content of the put in a loop, and start as the thread, button just open a thread,

CodePudding user response:

refer to the eighth floor rabbit party at large response:
really think impassability you didn't understand the basic concepts of the execution of a program logic, but where are work directly to fit the courage,

Your problem can analogy

You press the switch, the TV will continue to play, then you was just a switch button events, continue to play is a thread, so, you will need to continue to perform the content in a loop, and start as the thread, button just to open a thread,

Thank you very much for your reply, I almost understand now,
So, cycle in which good? For, while (true)?

CodePudding user response:

Really admire your buddy perseverance, come on.

CodePudding user response:

refer to fifth floor electric aircraft manufacturers reply:
Quote: refer to the third floor HZTLTGG response:
see questions before, should be written before the PLC to write code, now want to write a machine code, want to use c # write?
C # is the common language, and the thinking of PLC are not quite same, ready-made before the thinking of writing may be have a lot of problems
What you need is similar to a button, such as start reading data that a machine, but under a machine may have been writing the data, so reading is a process of continuous? If so, the idea should be read a background process to deal with, he is always in the execution, button just begins and ends with a background process control,


Is like this, can you tell me how to do?


Although there are many methods to achieve, I still recommend BackgroundWorker class to do, this is simple, the previous version has support

You can see the MSDN https://docs.microsoft.com/zh-cn/dotnet/api/system.componentmodel.backgroundworker? first View=.net 5.0

Means a DoWork BackgroundWorker event, you write an infinite loop in this event, judge receiving end what data,
Button in the event to the object to perform. RunWorkerAsync (); Methods line

CodePudding user response:

If completely according to your ideas, but also can implement, is to write in the button a while (true) infinite loop, read data, just such a program interface will be stuck, because read threads and drag the thread is the same interface, you infinite loop over there, the mouse to drag the fixed interface, add an Application in the loop. DoEvents (); Statements, can let the program every loop handle other events, can alleviate the problem of stuck, but this method is not very quiet and tastefully laid out,
  •  Tags:  
  • C#
  • Related