
- VBForums
- .NET and More
- C#
- 1.0-1.2 Two time thresholds are supposed to trigger two distinct actions without simultaneity
-
Dec 17th, 2023, 12:31 PM
#1
Thread Starter
New Member
Two time thresholds are supposed to trigger two distinct actions without simultaneity
Dear gentlemen,
I have been designing some app with VS2005 C#.
I intend to compare two distinct time thresholds designated 'pulltime' and 'releasetime' with current time picked up from the device the app is deployed and run.
Once the app is launched the user is intended to input two distinct time thresholds: 'pulltime' and 'releasetime' into two textboxes.
Once upon certain button on the form is hit timer begins to compare recent time picked from the device every 1000 ms.
When the 'pulltime' threshold is reached, certain coil should be pulled up, as timer ticks away the 2nd threshold 'releasetime' is approaching, thus when reached the same coil should be released.
The app operates without throwing exceptions, first off when the 'pulltime' is reached it pulls coil, but when 'releasetime' is reached it initially releases coil but in a second pulls it up again.
To give you an idea what I am trying to accomplish I add some code below:
First off I input 'pulltime' and 'releasetime' in the two textboxes as the strings:
string pulltime=TextBox1.Text; // input 'pulltime' as string
DateTime pulltime1=DateTime.Parse(pulltime); //convert string into date time
string releasetime=TextBox2.Text; //input 'releasetime' as string
DateTime releasetime1=DateTime.Parse(releasetime); //convert string into date time
The code below stands for pick up recent date time of the device on which app is run, extracts only time from DateTime
object, converts it into the string to display on the form, and then converts it into Date Time object again:
DateTime dt=DateTime.Now; //pick up recent date time of the board each 1000 ms
string dt1=dt.TimeOfDay.ToString(); //extracts only time, converts into string to display on the form
DateTime dt2=DateTime.Parse(dt1); //converts the string into date time object to compare with lower and time upper
//thresholds
the 3rd section of the code below is to compare recent time of the device with pulltime1 and releasetime1 thresholds
Int32 result=DateTime.Compare(pulltime1, dt2); //before dt2 reaches pulltime1 the value is 1, from the moment it has
//reached its value is -1
Int32 result1=DateTime.Compare(releasetime1, dt2); //before dt2 reaches releasetime1 the value is 1, from the
//moment it has reached its value is -1
When code runs on the device first off the lower threshold is reached the coil pulls up, time runs to the upper threshold
and upon it is reached the coil is released, then in one second is pulled up again and begins cycling around pulled and
released actions, until I deliberately cease the application.
Could you please take me into understanding, how this simultaneity of the actions could be avoided?
How to enhance this code, to make it perform only once pull up coil action when the lower threshold is reached, and only once release coil action when the upper threshold is reached?
Faithfully,
N.Kv.

- VBForums
- .NET and More
- C#
- 1.0-1.2 Two time thresholds are supposed to trigger two distinct actions without simultaneity
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|