C# :: Wait For Thread To Finish Without Using Sleep?

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


ADVERTISEMENT

C# :: Sleep / Wait - Unity 3D

Jun 3, 2013

I have been trying to make a sleep function in C# that will allow the game to be briefly paused when played. I am using Unity 3D.

View 2 Replies View Related

C++ :: Parsing Of Char Array Won't Finish

May 6, 2013

I have some cpp code that is looping through an array of char looking for a delimiter. The code saves the chars in a string until it finds the delimiter, then it adds the string to a vector of string and continues processing.

The input char array is,
Cl.N1C=CC=N1.HCl
the delimiter is '.', so the parsed strings should be,
Cl
N1C=CC=N1
HCl

The code seems to work find for the first two strings, but then it seems to stop and not find the third string.

This is the code,

Code:
#include <iostream>
#include <vector>
#include <string>

[Code].....

...then nothing. The function returns to the calling code, but may not have returned normally, it is hard to tell.

This appears to work up to a point, but does not find the last string HCl. The size of the char array that is passed to the functions prints as correct (16), so the for loop should process all 16 characters in the array. I don't see here why it stops.

This was compiled using g++-3. Some of the unusual syntax results from this being a cpp function that is called from fortran. The char array that is passed to the cpp prints as correct and has the correct size, so I don't think that is part of the problem.

View 5 Replies View Related

C# :: One Thread Trying To Pass Data To Another Thread Using Serial Port

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

C/C++ :: Getline Won't Wait For Input

Jun 6, 2014

Down on line 74, it does not wait cor an input, it simply says ...you failed.

#include <iostream>
#include <string>
#include <Windows.h>
#include <cstdlib>
using namespace std;
//prototyping--
void flater();

[Code] ....

View 6 Replies View Related

C++ :: Program Output That Doesn't Wait For Replies But Still Captures Them

Jul 21, 2013

I am trying to write a program that can communicate over a very latent internet connection involving a cellular modem. I have some software packages that handle all the telnet like business and will pipe stdout and stdin to a program I can have it execute.

The problem I am running into is that I have to send about 900 ASCII commands to an instrument to request data but it takes about a second between when a command goes out and when a reply comes back. This will wind up taking a very long time and I am looking to speed it up. All of the commands are independent of the reply so what I need to do is create a program that can send all 900 commands with maybe 10ms break between them and to not wait for a reply. It then needs to read the replies and write them straight to a file.

It seems like this should be achievable in C++ but I only have a very basic understanding of the language and thus am not sure where to start.

I am open to using other languages but thought C++ would be a reasonably good start so I can distribute the program to my coworkers. All of our work machines are Windows but if there is a simpler solution from Linux, I should be able to work something out. I'm just trying to avoid complication.

View 5 Replies View Related

C/C++ :: Can Client Wait To Open A File Until Server Has Made It?

Sep 30, 2014

I have a client/server program. My Client process spawns my server process using a `fork()` and `system()` call. The client and the server are meant to communicate to each other through named piped, that is a requirement of my homework. The client and the server are supposed to initially send a message to the other one, through a pipe, to confirm that a connection is made. My issue is that my client is trying to open one of the named pipes before the server has a chance to make it. This doesn't always happen though. Occasionally, it will run fine. Is there some way to synchronize this?

My overall goal is to get a filename and search target from the user, send those to the server through a named pipe. And the server searches for the target and sends info back.

OUTPUT:

Client: PID 2986 - Running on Tue Sep 30 20:59:28 2014
Client: PID 2986 - Enter File Name: largeSampleText.txt
Server PID 2988 - Running on Tue Sep 30 20:59:32 2014
Server: PID 2988 - Synchronized to Client.//This means the client-to-server fifo is working
There was an error opening serverToClientfifo//This means client couldn't open the server-to-client fifo
error is: 2//This means the fifo doesn't exist yet

[Code] ....

CORRECT OUTPUT:

Client: PID 2542 - Running on Tue Sep 30 20:58:44 2014
Client: PID 2542 - Enter File Name: largeSampleText.txt
Server PID 2557 - Running on Tue Sep 30 20:58:54 2014
Server: PID 2557 - Synchronized to Client.

[Code] ....

RELEVANT CLIENT CODE:

int main() {
char requestedFileName[1024];
//Get initial information on the client
pid_t clientPID = getpid();
time_t currentTime = time(0);
char* stringTime= ctime(¤tTime);

[Code] ....

I tried creating both of my fifos in my client and my output changed to this

Client: PID 3150 - Running on Tue Sep 30 21:23:17 2014
Client: PID 3150 - Enter File Name: largeSampleText.txt
Client: PID 3150 - Enter Target:
Server PID 3153 - Running on Tue Sep 30 21:23:21 2014
was
Client: PID 3150 - Input File >>>largeSampleText.txt<<<
Client: PID 3150 - Target >>>was<<<
Client: PID 3150 - Synchronized to Server
Server received unexpected connection message
Message: was
Terminating

So It appears like the client went ahead and put `requestedFileName` and`requestedTarget`into the pipe and the server read out `requestedTarget` instead of the connection message. Not sure why though

View 1 Replies View Related

Visual C++ :: Create Process And Wait For Input Idle

Feb 13, 2014

I have a problem with creating a process and waiting until the main window of the new process was shown. I thought I can wait for it with

WaitForInputIdle(pi.hp,INFINITE);

But when the function returns, the handle of the main window of the new process is not available. If I include also a ::Sleep(), the new window is available. Sleep is a bad solution. How can I do it?

View 3 Replies View Related

C# :: How To Get Monitor Out Of Sleep Mode

Jul 12, 2012

How can you get a monitor out of sleep mode in c#?

I tried the following, but then the monitor wakes up and falls back to sleep mode immediately.

Code:

uint SC_MONITORPOWER = 0xF170;
uint WM_SYSCOMMAND = 0x0112;
SendMessage(this.Handle, WM_SYSCOMMAND,
(IntPtr)SC_MONITORPOWER, (IntPtr)(-1));

View 1 Replies View Related

C :: Sounding A Beep While Using Sleep

Feb 22, 2015

I need to be able to sound an alarm (a beep) for 10 seconds in C.this beep has to mirror a sleep period, before the code loops back to the beginning. Now I've got the loop sorted and I can make it beep and sleep, however the beep follows 10 seconds after the sleep..Both the beep and the sleep need to happen at the same time..

View 3 Replies View Related

C++ :: Copy And Paste Function From Other Source Program Doesn't Wait For Input

Nov 27, 2013

I'm working on a project that requires to make modifications to certain functions. So, I'll copy and paste the function to a new source code so I'm just working on the function with the entire program running. When I run the function by itself, it works fine. But when I copy and paste the function back to it's spot, the program doesn't wait for input at the cin.getline & it did wait when I ran just the function by itself. I'm using Dev C++ if that makes a difference.

View 2 Replies View Related

Visual C++ :: What Header For Sleep Function

Jan 26, 2014

I have been googling for a long time to find the header used with sleep().

View 5 Replies View Related

C++ :: Sleep Function When Drawing Analog Clock

Jan 19, 2015

Make an "analog clock" that is, a clock with hands that move. You get the time of day from the operating system through a library call. A major part of this exercise is to find the functions that give you the time of day and a way of waiting for a short period of time (e.g., a second for a clock tick) and to learn to use them based on the documentation you found. Hint: clock(), sleep().

OK, I wrote below code. It is in its primary stages and has not been completed yet.

#include <GUI.h>
#include <time.h>
#include <iostream>
using namespace Graph_lib;

[Code] .....

I expect the system in void clock_hands() (line 38) attaches hour1 (line 41) then waits for 1000 ms (using Sleep(1000)) then detaches hour1 and attaches hour2 this time. But it doesn't occur in practice. When the system reaches Sleep(1000); it seems to go into a comma! It doesn't show the hour1 so seeing the movement of clock ticks by the clock's hands will not be possible.

View 5 Replies View Related

C++ :: Using Clear Device And Sleep Functions In Graphics

Dec 14, 2014

I have a college project which is a car racing game using C++ and the old-school graphics library BGI. After I draw the map and placed the objects(Car,obstacles,road's borders etc..)I added Sleep(); function to the function named Obstacles(); but the problem is, I can't move the car with the right&left arrows.a

Another problem,If I added a cleardevice(); command all objects disappears only the obstacles function keeps working. the Code is here:

char c;
do{
c = (char)getch();
if (c == KEY_LEFT) {
x = x - 10, x1 = x1 - 10;
} if (c == KEY_RIGHT) {
x = x + 10, x1 = x1 + 10;

[code].....

note: this is not the whole code, it's only a small portion of it, not a debugging question only need a hint how to fix it.

View 3 Replies View Related

Visual C++ :: Notification Supposed To Be Sent Out During Forced Sleep In XP?

Oct 2, 2012

I run the following API to put Windows XP SP3 into sleep (or standby mode) from a worker thread:

Code:
BOOL bForced = TRUE;
SetSuspendState(FALSE, bForced, FALSE);

Then in the main thread, while processing window messages:

Code:
LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
if(message == WM_POWERBROADCAST) {
if(wParam == PBT_APMSUSPEND) {
AddLogMsg(_T("SUSPEND event received"));

[Code] ....

So when SetSuspendState is called with request for a 'forced' sleep mode, the PBT_APMSUSPEND notification is never broadcast. Only if I set forced parameter to FALSE I receive it.

PBT_APMRESUMEAUTOMATIC is received in either case.

PBT_APMSUSPEND is always received when run on Windows Vista/7.

View 1 Replies View Related

Visual C++ :: How To Call Sleep Function Prototype

Dec 23, 2012

I have two problems with the code below:

1. I cannot find a header file to #include that has the sleep function prototype.

2. When I add my own sleep function prototype, I get an unresolved external reference error (for _sleep, not sleep).

What must I #include to get the sleep function prototype? What lib must I include in the linker configuration to resolve the external reference? (I suspect that if I #include the correct header file, the second question might become moot.)

The "man page" at [URL] .... says the header file is <WinBase.h>. But #include'g only <WinBase.h> results in compilation errors.

A response marked "answer" at [URL] ..... says <windows.h> [sic]. #Include'g only <Windows.h> does eliminate the compilation errors.

But apparently that does not bring in the sleep function prototype. Neither does also subsequently #include'g <WinBase.h>. (Which seems to be #include'd by <Windows.h> anyway.)

But even with my own function prototype shown below, I get an unresolved external reference for _sleep. Is that a symptom of my problem: my sleep reference is changed to _sleep? If so, how can avoid that?

According to "man page" (see link above), the external should be resolve in kernel32.lib. And kernel32.lib does appear in the "Additional Dependencies" list under Configuration Properties Linker Input.

Since I am not using C++ features, I tried setting "Compile as C" under Configuration Properties C/C++ Advanced, to no avail.

My code....

#include "stdafx.h"
#include <stdlib.h>
#include <time.h>
#include <Windows.h>
void sleep(DWORD msec); // added later
int _tmain(int argc, char* argv[])

[Code] ....

View 3 Replies View Related

Visual C++ :: Drawing Analog Clock - Sleep Function

Jan 19, 2015

The question says: Make an "analog clock" that is, a clock with hands that move. You get the time of day from the operating system through a library call. A major part of this exercise is to find the functions that give you the time of day and a way of waiting for a short period of time (e.g., a second for a clock tick) and to learn to use them based on the documentation you found. Hint: clock(), sleep().

OK, I wrote below code. It is in its primary stages and has not been completed yet.

Code:
#include <GUI.h>
#include <time.h>
#include <iostream>
using namespace Graph_lib;
//---------------------------------
class Dynamic_clock : public Window {

[Code] .....

I expect the system in void clock_hands() (line 38) attaches hour1 (line 41) then waits for 1000 ms (using Sleep(1000)) then detaches hour1 and attaches hour2 this time. But it doesn't occur in practice. When the system reaches Sleep(1000); it seems to go into a comma! It doesn't show the hour1 so seeing the movement of clock ticks by the clock's hands will not be possible.

[URL] ....

View 14 Replies View Related

C++ :: Access Objects From Another Thread

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

C++ :: Passing Parameters To A Thread

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

C++ :: Thread Chaining And Latency

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

C/C++ :: Thread Appears To Run After SetEvent

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

Visual C++ :: Add To Listbox Thread

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

Visual C++ :: How To Check Thread With MFC

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

C++ :: How To Decide Which Type Of Thread To Use

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

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 View Related

C++ :: How To Call A Thread By A Function Pointer

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







Copyrights 2005-15 www.BigResource.com, All rights reserved