C Sharp :: Counting Execution Time Of A Task?

Nov 9, 2013

I am checking out this simple piece of code:

private void button1_Click(object sender, EventArgs e)  {
            Stopwatch sw = Stopwatch.StartNew();  
            Task Task1 = Task.Factory.StartNew(() =>  {
                    Console.WriteLine("Task1 started in : "+ " "+sw.ElapsedMilliseconds);
                    Thread.Sleep(4000);
                    Console.WriteLine("Task1 finished in : " + " " + sw.ElapsedMilliseconds);
                }
                );
        }

and the results are :

Task1 started in : 2 in milliseconds
Task1 finished in : 4015 in milliseconds.

The problem is, that if i count the time with an external device, just like the timer of my watch or my cellphone s,the total time is 4,8 or 4,9 seconds, which i wouldn t expect that to happen.

The first thing i ve thought, is that it takes the ThreadPool about 800msec or 1 sec to create the thread so as to execute this task, but even if it is so, shouldn t the stopwatch count the time precisely?So , why is there a deviation between an external timer and the stopwatch ?

View 1 Replies


ADVERTISEMENT

C/C++ :: Round Robin Execution With Gantt Chart - Arrival Time And Burst Time

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

C :: Execution Stopped Every Time Try To Add Data From Scanf

Nov 12, 2013

this is a syntax i've been trying to run. apparently it stopped as i entered the first value. this is the value i am trying to key in

Initial House Cost 67,000 62,000 75,000
Annual Fuel Cost 2,300 2,500 1,850
Tax Rate 0.025 0.025 0.020

my syntax are as below

Code:

#include <stdio.h>
#include <conio.h>
int main(void) {
float houseInt1 , houseInt2 , houseInt3 ;
float fuelAnnual1 , fuelAnnual2 , fuelAnnual3;
float taxRate1 , taxRate2 ,taxRate3;
float total1 , total2 , total3;

[code]....

View 9 Replies View Related

C++ :: Execution Of Certain Commands - Setting Device Time

Sep 10, 2013

I got a assignment in which i have to write codes for execution of certain commands.

One of the command is set_time. if user enters set_time 12:12:12

The time should get reset to 12:12:12 no matter what it is now.

View 7 Replies View Related

C++ :: Measuring Execution Time Of Static And Dynamic Binding

Jan 11, 2013

consider the code bellow

#include<iostream>
#include<ctime>
#include<boost/progress.hpp>
using namespace std;
class parent {
public:
virtual void dynamic_display(){

[Code] ....

I am getting the following as output

Calculating....Static Function is called1times
The number of processor clicks is0time is0
Calculating....Dynamic function is called1times
The number of processor clicks is0time is0
Static Function is called2times
Dynamic function is called2times
Static Function is called3times
Dynamic function is called3times

I am actually trying to calculate the time to execute a statically binding method and a dynamically binded one.consider only the first four lines in my output. Why am i not getting the actual result.

View 3 Replies View Related

C/C++ :: Sequential Matrix Multiplication - Error In Execution Time

Apr 30, 2014

I wrote program for Sequential matrix multiplication .But after execution for any input value( ex. 100,150,400) it shows the execution time is 0.000 msec.

#include <stdio.h>
#include <math.h>
#include <sys/time.h>
void print_results(char *prompt, int N, float *a);
int main(int argc, char *argv[])

[Code] ......

View 2 Replies View Related

Visual C++ :: Obtaining Actual Effective Execution Time Per Thread With Hyperthreading

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

Visual C++ :: Read Table And Get All PNAME Into Combobox - Reduce Query Execution Time

Nov 14, 2014

My table:

Code:
Database name: test & Table name : Profilemaster
+-----+--------+
| PID | PNAME |
+-----+--------+
| 1 | APPLE1 |
| 2 | APPLE2 |
| 3 | APPLE3 |
| 4 | APPLE4 |
| 5 | APPLE5 |
| 6 | APPLE6 |
| 7 | APPLE7 |
| 8 | APPLE8 |
| 9 | APPLE9 |
| 10| APPLE10 |
+-----+--------+

I like to read the table and get the all PNAME into the combo box.

Using the below code i can read the table, but while loop takes 2 seconds to read 10 records in the Profilemaster table.
How can i reduce the reading time?

My Code is
void MainScreen::OnreadProfileName() {
CDatabase database;
CString SqlString;
CString sDsn;
CString pname;

sDsn.Format("Driver={MySQL ODBC 5.2 ANSI Driver};Server=localhost;Database=test;User=root;Password=client;Option=4;");

[Code] ....

Is any other way to reduce the query execution time?

View 6 Replies View Related

C Sharp :: Lock Thread Till Execution Is Finished?

Jun 26, 2012

I have a event called dataTree_AfterSelect in which I have some code which I want to execute as atomic operation like this:

protected void dataTree_AfterSelect(event params)
{
code that should not be disturbed
}  

What is happening now is, I am able to select another node of tree & in that case another execution of above function starts causing a garbled result.

What I want is, user should be able to click on tree node but execution of code block should only start after first execution is totally over.

View 4 Replies View Related

C++ :: How To Start Counting Time When Program Starts

Apr 7, 2013

I want to know if there is a function or library that starts counting time when the program starts. Because I'm making a program that is dependent on time.

Pseudo code

time starts
if ( seconds % 2 == 0 ) {
counter++;
}

View 2 Replies View Related

C/C++ :: Time Delay Function - Timer Stop Counting If Any Key Pressed

Aug 29, 2014

My code is given below:

cout<<"1. runtim";
cout<<"2.tims";
cout<<"Your selection will be automatically neglected within (function to be inserted for time ) ";/* insert timer here */
cout<<"What kind of process u need to do";
.
.
.
.

I have 2 questions

1.the timer function has to be such that when any key is pressed in between the specified time its has to stop its counting and go to the nest line and functions . i checked sleep function but if any key is pressed its does not break out of the sleep program and execute the next command

2.and if the timer has completely finished running then it has to skip few lines and execute the program .

View 14 Replies View Related

C Sharp :: Time Table Of School?

Mar 22, 2013

I have project "Time Table of school". How it possible logically as well as visually in .NET. it contain all teachers name and their periods. when any one absent then we enter the name of teacher or course name, highlight the absent teacher periods and then generate arrange period list and print it. when it highlight timetable we click on them and show all other teacher names who are free at this time.......

what controls are need in .NET with c#. it will be desktop application,

View 10 Replies View Related

C# :: Send Multiple Files Over Tcp At The Same Time In C Sharp?

Nov 29, 2010

I have a tcp client - server implementation running in the same program, on different background worker threads. There will be instances of this program on multiple computers so they can send and receive files between each other. I can send files sequentially between computers using network stream, but how would I send multiple files at the same time from computer A to B.

Sending multiple files over one connection ( socket ) is fine, but having multiple network streams sending data to a client, the client doesn't know which chunk of data is apart of which file ?

View 3 Replies View Related

C Sharp :: Show Elapsed Time Of Windows Form?

Aug 6, 2012

In my class I'm trying to display the elapsed time as my label on a windows form. I've been reading up on all the different articles online and have tried these three methods all with the same result:

1. Using the System.Timers class
2. Built in Timer sub-class
3. Defining directly inside of my class the StartTime, etc. variables.

All of these still result in the following error:
Cross-thread operation not valid: Control 'User_Interface' accessed from a thread other than the thread it was created on.

Currently, my windows form is being called by another class, but I'm not sure if this is the cause of the problem.

This is a sample of the code that I'm currently using to show the elapsed time:

private void OnTimedEvent (object source, ElapsedEventArgs c)
{
TimeSpan time;  
currentTime = DateTime.Now;

[Code].....

View 5 Replies View Related

C Sharp :: Show Only Date Not Time In Visual Studio

Feb 1, 2013

How to show only current date not time in webforms in visual studio as for date and time code is

Label1.Text = DateTime.Now.ToString();

What for only date not time

View 3 Replies View Related

C Sharp :: Compare Date In Registry With Local Time?

Feb 2, 2013

The first time my application opens up, it should get the local date out of the System and store this in a registry key. But the second time it should get the date stored in that registryKey and compare it to the date right now.And there is where I am stuck, I just don't know how to get the date out of that key and compare it to the date right now.

This is my code:

RegistryKey key1;  
        private void btnTrial_Click(object sender, EventArgs e) {
            DateTime current = DateTime.Now;  
            key1 = Registry.CurrentUser.OpenSubKey("myKey");    
            if (key1 == null)

[code]....

at the last "if" statement it should compare the date stored in the key with the DateTime.Now.

View 9 Replies View Related

C Sharp :: Generate Automatic Alerts With Snooze Time Before Targeted Date And Day Before

Nov 20, 2012

i want to create an application which generates popup alerts at the day of event occurs as well as a day before the event will occur in a specific time interval as well.. events are stored in database and they are all date time fields .. so i want to link those fields to create popups ..

View 2 Replies View Related

C Sharp :: How To Pick Date / Time When Serial Port Starts Reading And Also When Stops

Aug 18, 2014

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.IO.Ports;

[Code] ....

How to pick date / time when serial port starts reading , and also when reading stops ?

View 2 Replies View Related

C :: How To Suspend An Ongoing Task

Aug 6, 2013

Here is what I am trying to do. I am reading from a socket. On receipt of specific data from the socket I have to start some computation (takes more than 5s). But if there is another input from the socket when the computation is in progress I need to disregard the ongoing computation and start all afresh. I have not come across any method which could suspend the ongoing task in the same context. I have thought of running computation in a separate thread. But I feel there must be some other methods doing it in the same context which I am unaware of. And, is my understanding correct that process would take up the new task only after completing the previous computation (which I do not want).

View 6 Replies View Related

C++ :: Input Edit Task

Jan 20, 2015

how i am using wxDev-c++ and i need to make.Tasks would include: use a class or struct variable, and create a program that can perform the following actions:

1. The data provided by the user to enter the keyboard.
2. The display of the stored data.
3. edit the data.

Example of data: name surname age.

I Try like it,its let me input and save it but how to edit it or i am doing it bad?

#include<iostream>
#include<fstream>
using namespace std;
int main()

[code]....

View 5 Replies View Related

C++ :: Print Out All Task Orderings

Jul 20, 2013

Given N tasks (numbered 1-N) and a series of task restrictions (do task 3 before task 2) print out all possible task orderings.

Example input:
3
3 2

Explanation: there are 3 tasks and task 3 must be done before task 2 (each restriction will have its own line)

Example output:
1 3 2
3 1 2
3 2 1

View 9 Replies View Related

C++ :: Function Overloading (OOP Task)

Feb 27, 2013

I have been asked to create a program to overload a function which should accept and print first one integer and then two integers. Here is the code i have produced so far: [URL] ....

Code:
#include <iostream>
using namespace std;

//Overloading f1 three ways

int f1(int a);
double f1(double a);
long f1(long a);

[Code] .....

I am aware the code should work. my only concern is the error i receive on line 12. I am certain there should be a value in the bracket but i dont know what.

View 11 Replies View Related

C++ :: How To Get List Of Applications Showing By Task Manager Through API

Oct 21, 2014

I am searching for a way/api through which i can get list of Applications as showing by task manager inside Applications tab. Is there any way?

View 3 Replies View Related

C++ :: Showing All Running Processes Like In Task Manager

Oct 7, 2014

I want to show all running processes of windows.

my motive is whenever any running process closes/quits whether it be console or window based on windows it notify(s) me or user that some .exe has been closed.

View 1 Replies View Related

C# :: Design Pattern For Task Notification System

Feb 24, 2014

I am looking a good design pattern that takes a combination of a Observer Design Pattern and Command Design Pattern.

Observer Design Pattern:

Subject - ISystem
ConcreteSubject - "Different Types of Systems"
Observer - INotifier
ConcreteObserver - "Different Types of Notifier's"

Command Design Pattern: Used to create a task. "Different Types of Task" ....

View 4 Replies View Related

C++ :: How To Create Member Function To Represent Embedded Task

Jun 17, 2014

The following code is an example of how task are created with micro cos III in c. I am trying to figure how to create similliar code in C++. My problem is how do I instantiate objects and how to use member functions to represent task. Within the create task routine the address of function is passed as argument. How do I do this in C++? Will I need more than one class? New to embedded C++.

/*!
* @brief LED Flasher Task
*/
void
led5_task (void * p_arg)
{
OS_ERR err;
(void)p_arg; // NOTE: Silence compiler warning about unused param.

[Code]...

View 2 Replies View Related







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