C++ :: Creating A Thread To Display Time
May 5, 2014
I want to add a timer(clock) to my application so that it displays the system time and refreshes every second.
I have this code but it only fires once.
// this is at the top of the application
Code:
HANDLE m_threadClockTime= NULL; Code: int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine,
_In_ int nCmdShow)
[Code] ....
But this code only fires once? How can I get this to fire every second (without locking up the entire application in between)....
View 5 Replies
ADVERTISEMENT
Oct 6, 2014
I need using CSemaphore class in MFC C++ application. I have an edit1 box with multil ine and each line has a string. I'm trying to loop through edit1 box and for each string to start a thread that is using the string for specific function. I'm trying to limit the run of only one thread at the same time with semaphores but all treads start at the same time.
So when i click button1 i loop through edit1 box and start threads:
Code:
void CMFCApplication1Dlg::onButton1Click() {
int i, nLineCount = edit1.GetLineCount();
CString strText, strLine, mesaj;
for (i = 0; i < nLineCount; i++) {
[Code] ....
While looping through edit1 box multi line and starting the threads:
Code:
UINT CMFCApplication1Dlg::StartThread(LPVOID param) {
WaitForSingleObject(semafor, INFINITE); // wait for semafor to signal
THREADSTRUCT* ts = (THREADSTRUCT*)param;
// here i'm doing some operations with the string from edit1 box
ReleaseSemaphore(semafor, 1, NULL); //release the semaphore for next thread to begin
}
Instead of running only one thread at a time all threads start. What am i doing wrong ?
View 14 Replies
View Related
Mar 11, 2015
I am having a strange problem trying to display a dialog from a UI thread. The dialog simply fails to display. I have a function DisplayFlashBox(), which creates the UI thread:
CUIThread* CIMUIHelper:: DisplayFlashBox(const CString &sMessage, const int nInstrumentUID) {
CUIThread *pThread = new CUIThread();
pThread->SetString(sMessage);
pThread->SetInstrumentUID(nInstrumentUID);
pThread->CreateThread();
[Code] .....
The dialog doesn't display. When I tried debugging, I found the OnInitDialog() method of CIMFlashBox class doesn't actually return. Very strange. I tried calling the DoModal() method instead of Create, but doesn't display the dialog either.
View 5 Replies
View Related
Jun 13, 2013
I'm looking for a function like GetThreadTimes, but one that gives correct results in a hyperthreading CPU.
For instance, if you start 2 threads on a CPU with 1 physical core and 2 logical cores, GetThreadTimes will say that both these threads use 100% CPU.
However, in reality they only use 50% each. Is there a function that returns correct results, or is there another workaround?
View 8 Replies
View Related
Feb 20, 2013
I created a program to display time continuously so it auto updates every sec but the issue is i cant integrate the code in the main program because to make time update continuously it needs a loop a infinite loop so none of the rest program gets to work. My q is : is it possible to display time continuously and make the rest of program continue normally? like a multi thread program because i want to display time every sec in the bottom of program. By the way this is console app not gui
View 8 Replies
View Related
Feb 18, 2015
I am creating a class called time and we've had to do operator overloading for <, > , <=, >=, ==, !=, ++, --, >>, <<, * , +, and -.
Well I have done and error checked them all. The only one I cannot seem to get right is the minus and its because of the error checking. I am having issues with times like this
t1 = 0:0:2:3
t2 = 0:0:1:4
t1 - t2 should equal 0:0:0:59 but it returns 0:0:1:-1.
(days:hours:minutes:seconds)
I need it to check for all cases and I just do not know how. Here is the code I have so far:
time operator- (const time& x, const time& y){
time subtract;
subtract.days = x.days - y.days;
subtract.hrs = x.hrs - y.hrs;
subtract.mins = x.mins - y.mins;
subtract.secs = x.secs - y.secs;
[Code] .....
View 1 Replies
View Related
Jul 30, 2014
I have a class which I wrote and one of its object is "SerialPort" .NET class. In my MainWindow I created instance of my class called "SerialPortComm", then I send through some functions of mine, commands to the Serial Port, and I receive answers through "DataReceived" event.
But when I trying to use Dispatcher.BeginInvoke to write my data I have received (successfully), nothing shows on the RichTextBox which I'm trying to write to.
What can caused that, and How I can make it works?
SerialPortComm.cs
public partial class SerialPortComm : UserControl {
public SerialPort mySerialPort = new SerialPort();
public void Open_Port(string comNumber, int baudRate) {
mySerialPort.PortName = comNumber;
mySerialPort.BaudRate = baudRate;
[Code] ....
View 7 Replies
View Related
Feb 14, 2013
I'm trying to display the AM/PM on my program:
Also is there a way to display the time only instead of the date? How will i change the program to display the time in standard 12 hours, instead of 24 hours?
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
time_t tim;
time(&tim);
cout << ctime(&tim);
}
View 1 Replies
View Related
Mar 16, 2012
How to get system Date and Time and display it in the format DD/MM/YYYY ??
View 2 Replies
View Related
Jul 25, 2012
How to display a message only for 10s using timer in c ....
View 1 Replies
View Related
Feb 16, 2013
i need to display the current time and date in my program and use variable to store each of the time values like
a = 10
b = 29
c = 31
printf(``%d : %d : %d``, a,b,c);
which then give the output as - 10:29:31
How to save the time in variables in C....
i am using C in windows 7 and my complier is Bloodshed Dev C++
View 7 Replies
View Related
Feb 12, 2013
I'm doing a project where I have to store information gathered (temperature and the time it was taken in seconds) in two separate vectors. After an unknown amount of data has been entered, and the end-of-file has been reached, I have to display the highest temperature and the time(s) it occured (bear in mind that the highest temperature may be recorded more than once). The output of that part should be as follows:
Highest temperature: 51
Recorded at time(s):
22:45
2:27
Something like that. The time should also be converted to hours and minutes. To the point: I've done some research on bubble sorting, but they only use it for arrays.
View 3 Replies
View Related
Mar 10, 2015
This is a round robin execution. with gantt chart. arrival time and burst time. I think there is an error in my formula to get the right answer,i cant resolve it but my program is running. What is the code or the right formula??
#include<stdio.h>
int main(){
int i,j=0,n,time,remain,flag=0,ts;
int sum_wait=0,sum_turnaround=0,at[10],bt[10],rt[10];
int ganttP[50],ganttStartTime[50];
printf("Enter no of Processes : ");
scanf("%d",&n);
remain=n;
[Code] ....
View 2 Replies
View Related
May 1, 2013
So I'm trying to learn how to use time for time based movement and what not. I did this only knowing the command time(&variable)
time_t timer;
int I, X;
void main() {
time(&timer);
X=timer;
while(I==5) {
[Code] ......
There's probably some other better way to do it... Obviously but for now I see it as putting current time in X.
start while
take in time constantly until I is 5
constantly asking is time>X(preset time 5 seconds ahead)
if it is
display message and add one to I
Why doesn't this display my message after 5 seconds?
View 1 Replies
View Related
Apr 19, 2014
I created class called students which suppose to store students names of in array but when I call the display function it display only the first name. but I want it to display names depending on the array size.
#include <iostream>
#include <sstream>
using namespace std;
const int SIZE=5;
[Code]....
View 3 Replies
View Related
Dec 6, 2013
I know this is more simple than I am making it out to be. I have a solar panel hooked up to an 8-Bit ADC and linked into my Microprocessor. I am trying to take the Binary readout from the ADC and convert it to a decimal number to be displayed on the boards LCD display. I am wiring the ADC to PORTA on my Motorola Freescale Board. This is for a final project for my electronic systems class due on Monday...
View 3 Replies
View Related
Jun 25, 2013
I have the following code below. I am getting a memory access violation when accessing cmd->query_string in the loop function. The loop() function is running in another thread. The cmd object appears to be destroyed after calling the send_command function. How do I create an object on the heap and access the query_string.
std::list<my_command_message_que*> my_command_que;
void loop(){
if(my_command_que.size() > 0){
my_command_message_que * cmd = my_command_que.front();
std::cout << cmd->query_string;
[Code] ....
View 2 Replies
View Related
May 9, 2013
I've been using threading for a while, that was no needing parameters. so I used for example the following line :
_beginthread(functionName, 0, (void*)10);
and it worked great...
but now I have a function that has an int parameter (int num), and I dont know how to transfer it using _beginthread...
View 2 Replies
View Related
Mar 3, 2013
I was working on a problem that was best solved with chaining threads together using a blocking thread-safe queue. Eg threads A and B pass data to each other using a queue ... a simple producer consumer design A -> B. This has two benefits: 1) being that there is a buffer between the two threads to cache for a slow consumer and 2) allows for better throughput when loads of data are high because the two can run in parallel. Most of the time the design works well under load. but I found when pushing data through the threads intermittently, i.e. once about 0.5 seconds it ran poorly, mostly from what seemed to be latency introduced during the OS waking up of the consumer thread B.
What i have come up with to solve this issue is what i call an .... Its a wrapper around a basic thread safe queue and adds one extra function called .... The idea here is that if you have a simple case (or perhaps a slightly more complicated case) of two threads in a prod cons design and you know the producer will create or received the data, process it, and then push onto the queue, why not give the consumer thread a heads up to let it know the data is about to arrive. In this case call .... In this way you can have the consumer thread in a polling state anticipating the arrival of data and avoid the time to schedule it back to a running state.
Anyway, i have some code below and I was looking to get some feedback. I have tested it somewhat and it does improve the responsiveness quite substantially.
View 7 Replies
View Related
Apr 28, 2014
I don't know if I've setup the thread correctly or not, but its behavoir isn't what I'd expect. I'm creating the thread within a BN_CLICKED message
typedef struct my_TNFO {
HANDLE h_event;
HANDLE h_thread;
DWORD thread_id;
BOOL running;
BOOL init;
BOOL canceled;
[Code] ....
progd->count was devised to stop the thread when the recursion ended by posting a message to the main window. When it reaches 1, the def procedure sends the WMU_DISC_DONE message to set the event
All that *appears* to work; however, if I cancel the recursion thread, the list view continues to populate for a bit and then deletels all but 1 item though I send the message LVM_DELETEALLITEMS.
If I move the (tmp->canceled == TRUE) test inside of the do-while, the app gets loopy.
View 4 Replies
View Related
Feb 15, 2015
Startthread get called to launch to update list box.
a)is it the only way to pass string to the PostMessage?. my concern is that allocate using new in each iteration each time slows it down a bit.
b)does OnAddToListBox look memory leak free?.
c)What is the best way handle m_pThread at the end?. Any way to improve it?.
Code:
UINT CMyDlg::Dump(LPVOID lparam) {
HWND *pHndl = static_cast<HWND *>(lparam);
char buffer[200];
for (int i = 0; i < 100; i++) {
sprintf_s(buf,"user %d, data %s",i, "Connected");
[Code] ....
View 8 Replies
View Related
Feb 12, 2013
I use MFC Find console window and send key to console like this.
Code:
HWND w;
w = FindWindow(NULL, L"c:userspkrudocumentsvisual studio 2010ProjectsCleanVirusDebugCleanVirus.exe");
[Code]....
After program process success in console it not close console windows but it show like this in Output
The thread 'Win32 Thread' (0x1300) has exited with code 0 (0x0).
I think if I can check when VC will show this line, then I can use FreeConsole(); for close console windows.
View 3 Replies
View Related
Jun 7, 2014
There are gnu thread, c thread, posix thread and win32 thread which all can be used on windows platform.
How, why and when do I need them?
Code:
#ifndef C_THREAD_H_
#define C_THREAD_H_
extern "C"
{
#include <cthread.h>
[code]....
This simply won't compile with Visual C++ because there isn't any cthread.h header file there.
View 5 Replies
View Related
Nov 24, 2014
How to call a thread by a function pointer?
I get "error C2059: syntax error : '(' " on the indicated line.
Code:
#include <windows.h>#include <iostream>
using namespace std;
DWORD WINAPI Thread() {
cout << "ok" << endl;
return 0;
[Code] ....
View 9 Replies
View Related
Aug 27, 2013
I am writing a program, the trouble is is that it uses a single thread and is SLOW.
View 10 Replies
View Related
Apr 30, 2012
After i've created a thread,
Code:
Thread thread = new Thread(new ThreadStart(alpha.ThreadProc)); h
How to wait for that thread to finish without using Sleep?
View 8 Replies
View Related