C# :: How To Properly Handle Thread Failures

Feb 9, 2015

I have an application that uses an array of threads to call a method along with thread.join(). I was just wondering what would be the best way to handle the thread in case if one of the thread fails? Should I put a try catch block on the method that is being called or should I put the try catch block on the array of threads, or is there any other proper way to handle failed threads?

View 3 Replies


ADVERTISEMENT

C++ :: Handling Static Cast Failures

Oct 10, 2014

Is it possible to handle situations where static cast fails. I have a sample code written belo:

typedef struct test {
int a;
int b;
} tester;
void setevent(void *in) {
tester *recv = static_cast<tester*>(in);

[Code] ....

In above code when setevent is called with the tester object, there is no issue, but if we pass random value it leads to seg fault. This is because static_cast is not type_safe, but can it be handled in any other way?

View 1 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++ :: Calculate Something More Than A Var Can Handle?

Jan 1, 2013

Let's say I want to calculate something like PI using some algorithm, but with the number of digits I want to.

View 1 Replies View Related

C# :: How To Close Overlapped I/O Handle

Nov 6, 2012

Consider the following code which closes an overlapped I/O serial handle during application shutdown.

Code:

Win32Com.CancelIo(hPort);
Win32Com.CloseHandle(hPort);

It works fine under .NET 2.0 but after switching to .NET 4.0 it crashes on the CloseHandle. Removing CancelIO doesn't work.

What the correct way is to close an overlapped I/O handle? And why is there the difference between NET2.0 and 4.0?

View 5 Replies View Related

C :: Handle Cmd Line Arguments?

Jul 30, 2013

How to handle cmd line argument in c.

View 5 Replies View Related

C++ ::  how To Handle Async Operations

May 29, 2013

I've been thinking over this for long time... For example, when a button is clicked, print a string "clicked" after 5 seconds. (the button won't be blocked)

Thread should be the only way to do this:

btn.on_click = []() {
thread thrd([]() { sleep_5_seconds(); cout << "clicked" << endl; });
thrd.start();
};

the local variable thrd is destructed right after it starts, which may cause a crash, so use new operator:

btn.on_click = []() {
thread* thrd = new thread([]() { sleep_5_seconds << "clicked" << endl; });
thrd->start();
};

The thrd never get deleted

How would you solve problem like this?

View 2 Replies View Related

C/C++ :: How To Handle Exception In Constructor

Apr 14, 2012

If a class A contains an array of objects of another class B.. And in the constructor of A, while constructing objects of B, any one object throws an exception, then how can we guarantee to release all the memory acquired.. so that there is no memory leak..

class B{};
class A{
public:
  B Array[100];
  ...
};  

In the above code, if in constructor of A, suppose 99 objects of B are constructed successfully, but 100th object throws exception, then how can we guarantee to release all the memory acquired by the other 99 objects?

View 1 Replies View Related

C++ :: SDL Handle Mouse Motions And Clicks?

Sep 14, 2013

I have a game that I'm trying to create but I don't really know how to handle mouse motions yet. I have read the LazyFoo.net lesson 9. And I have too searched around on Google but haven't find any good article for what I want to do

But what I want is to check if the mouse is OVER the START button of the game and if the user has pressed the LEFT mouse button the game should START.

This works when I am hovering over the area there I want the mouse to do something:

Code:
else if (event.type == SDL_MOUSEMOTION)
{
if (event.motion.x == 0)
{
quit = true;
}
}

I do not know how to check this. The START and QUIT button is in the middle of the screen and I don't know how to position the mouse there either.

View 5 Replies View Related

C++ :: SDL - How To Handle Mouse Motion Input

Oct 19, 2013

I am using SDL 2.0. But I don't know how to handle mouse input. Do you think you can explain of how to do that? Or give me a link that explains that really great?

I know how to handle a mouse button that presses down for a sec.

Code:
if (event.type == SDL_MOUSEBUTTONDOWN){
if (event.button.button == SDL_BUTTON_LEFT){
// Do something . . .
}
}

But not how to handle the mouse input of what the mouse is hovering over and that.

Like in a start menu of a game. I want a button for example to appear blue when I hover over it and when I click on it. It should start the game for example.

View 6 Replies View Related

C :: How To Handle Sound And Music Files

Mar 11, 2013

I do not know any of the functions to do this, and when I looked on the internet all the functions I saw were mainly non-standard.

View 12 Replies View Related

C/C++ :: How To Handle Floating Point Error

Nov 7, 2013

And it is not running successfully... abnormal termination

View 3 Replies View Related

Visual C++ :: Passing File Handle To DLL?

May 6, 2013

I write a small application and using the following API to open the file:

hHandle = CreateFile(lpszFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

Then I pass the hHandle to a DLL exported function, in that function, I will call

DWORD dwFlags = 0;

ASSERT(GetHandleInformation(hFile,&dwFlags) != 0)

to check if the handle is valid. However, the assert fails. And I use GetLastError to get the error code 6, which means invalid handle.

What is the problem with my codes?

View 4 Replies View Related

Visual C++ :: Pass A Handle To A Function

May 5, 2013

Visual C++ 2010

I'm using SFML with Visual C++ and need to pass a handle to a function. I've tried to find this on the web with no luck.

The handle happens to be a sprite defined as: sf::Sprite Numbers(MyNumbers);

Now I want to pass "Numbers" to a function.

-
-
getFrame(Numbers);
-
-
???? getFrame(??????) {
Numbers.SetSubRect(sf::IntRect(0,0,63,63));
return ????
}

How do I do this?

View 1 Replies View Related

C++ :: How To Handle The Exceptions Not Caught By Try / Catch

Nov 2, 2014

Here is an example,

Code:

int main()
{
try{
int y = 0;
int x = 2/y;
}
catch(...)
{
cout<<"catch it"<<endl;
}
return 0;
}

If you try, you will find out that catch(...) couldn't catch exception divided by zero. How'd we catch such exceptions?

View 4 Replies View Related

Visual C++ :: How To Handle Open Document

Oct 11, 2012

I have an MFC program created from the app wizard. It is an MDI program, reading/writing text files using Serialize. I can read the document and know that the entire document was read into my buffer without any errors. This was verified by compaing the number of bytes read with the file length.

How do I get the document to display in my main/child window?

How do I read the document from the window so I can save it back to the file?

View 14 Replies View Related

C :: How To Handle Enum Checks In Function Arguments

Aug 31, 2013

As we know in C there is no checking if values passed to a function that takes enum are correct, that is if they have been defined in this enum. Example from Enums in C | Occasionally sane ([code] tags don't work on my fx 18.0.1 this is why I put in on pb): [URL] ......

Here c - How to check if an enum variable is valid? - Stack Overflow they say that common convention is add check whether value passed as the parameter is not bigger than the maximum value in enum. But how about situations when enum is composed of numbers from 1-20 and then from 500-510?

View 4 Replies View Related

C/C++ :: Automatic Cast Object To OpenGL Handle / ID

Oct 24, 2014

I programming currently something with OpenGL. Now I have written some wrapper classes, like Shader, Program .... All works fine, but I don't like to call Shader.GetHandle() every time I want to call a OpenGL function manually where I need the object handle/id. (GetHandle() returns the OpenGL ID of the object)

So now I wonder, is it possible to program it in C++ so, that I can put my objects to gl methods and c++ automatically pass the handle/id member to that function ? Is there maybe a operator that I can use for that?

For example:

The way I do it now:

Shader vertexShader();
glCompileShader(vertexShader.GetHandle());

The way I want to:

Shader vertexShader;
glCompileShader(vertexShader);

View 3 Replies View Related

Visual C++ :: WTL - Handle Splitter Position Changing

Sep 6, 2013

How can I handle splitter position changing?

View 2 Replies View Related

C++ :: Handle Exception In Multi-threaded Environment

Oct 24, 2014

Here is the code,

Code:
void foo() {
Acquiring lock
do something...
Func();
Releasing Lock
}

If the function Func throws an exception, there is potential deadlock issue. Then I handle exception like this,

Code:
void foo() {
Acquiring lock
do something...
try{
Func();

[Code] ....

Is this a good practice? I wonder how I can apply RAII in handling exception here.

View 2 Replies View Related

C :: Modifying Code To Handle Uppercase And Special Symbols

May 23, 2013

My code is currently reads in a string of lower case letters, identifying the occurrence of each letter.

Code:
#include <stdio.h>
#include <string.h>
int main()
{

[Code]....

My issue is that I want my code to read uppercase and special symbols. showing the occurrence of both.

Code:
else if(str[x] >= 'a' && str[x] <= 'z');
else if(str[x] >= '0' && str[x] <= '9');

However I struggle to implement it

View 3 Replies View Related

C++ :: 2D Game - How To Handle Drawing Order Of Object Visibility

Feb 9, 2015

In 2D games, what's the best way to handle the order of drawing objects? Because most games have a background, tiles to be drawn behind the player, perhaps tiles to be drawn covering up the player, etc. My point is, with my current setup of simply looping through all objects and drawing, I have no control over what objects are drawn on top of or behind the others. My best idea so far is to hold a vector of object pointers, each vector representing a different "visibility level", like so:

class Level{
//...
std::vector<Object> allObjectInstances;
std::vector<Object*> visibilityOne; //background objects
std::vector<Object*> visibilityTwo; //objects in front of background but not necessarily all the way in front
//and so on for more objects
};

If I go through with this, I'm wondering how I could loop through all my objects and add them to each vector, then shorten whatever I have to loop through for subsequent visibility vectors. handling the order of drawing objects?

View 6 Replies View Related

C++ :: How To Create CPP File That Will Handle Random Number Generators

Jul 23, 2014

How to create .cpp file (new class) that will handle all the random number generators (<random> library) that main could possibly access. When I looked for a way how to implement random generators the examples were always in the main function or in a class in the main.cpp (with no header file and the generator was not seeded as I imagine it should be = only once in a program).

Questions follows after this malfunction code.

main.cpp
#include "randomizer.h"
int main() {
Randomizer randObject(0, 10, 125); //Set bounds and seed generator
int mainVar = randObject.getRandInt(); //Store newly generated random number for future work

[Code] .....

1) So I think that I should somehow declare these generators and distribution in the header file. Is it like declaring int a;?

I tried writing std::default_random_engine defGen; into the header file which only silenced compiler's errors but defGen wasn't seeded.

I have seen some examples using auto a = randInt(defGen); (or maybe with the use of auto a = std::bind.... But what does auto represent? I can't use it in the header file.

2) Can I ensure that the randObject is seeded only once? If for examle I need randObject2 with different boundMax, can I still use the same defGen which was seeded the first time? That should ensure better "randomness" through the program, shouldn't it?

3) Is there better way (and easy too) to "interface" random number generators? The class in the end should provide "get" function to acces int, double, bool, signed/unsigned... or some other specialities like random prime numbers, etc.

If it is anyhow related I am using Code::Blocks IDE with GCC compiler (4.7.1)

View 4 Replies View Related

Visual C++ :: Free Image Library That Handle PNG Resolution

Mar 14, 2013

Need a free image library that can handle png xresolution and yresolution. I need it to be compatible with visual studio 6.0

View 1 Replies View Related

C++ :: Adding Overloaded Function To Handle Floating Point Numbers

Feb 2, 2013

I'm stuck on the last part of my program. The directions are the following~

Expand the program to add an overloaded function to handle floating point numbers (i.e., doubles). Include output for one list of integers and one list of doubles. Use this function prototype: double avgx(double&, double&, int, ...);

Compile and run. You should have one function named avg, one named davg, and two functions named avgx

My code does not compile and I think I'm not declaring my function prototype correctly?

#include <iostream>
using std::cout;
using std::endl;
#include <cstdarg>
// function prototype(s)
int avg(int, ...);

[Code] ....

View 2 Replies View Related

C :: Cannot Get Strstr To Work Properly

Aug 26, 2014

I am unable to get the string seaching function to work. it always says "Nothing found" I am stumped.

Code:

#include <stdio.h>
#include <string.h>
char tracks[][80] = {
"I left my Heart at Harvard Medical School",
"Newark, Newark, You suck balls",
"Dancing with a dork",
"From Here to maternity",
"The Girl from Iwo Jima",

[Code]....

View 3 Replies View Related







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