.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
323 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
In a windows C++ CLR project, on pressing a button (start) I initialize a counter (a chrono timer):
private: System::Void start_Click(System::Object^ sender, System::EventArgs^ e) {
clock::time_point start_runtime = clock::now(); // I create a time point "start_runtime"
// stuff here
}
I am trying to get the time point "start_runtime" to be available in other functions:
double get_timer_seconds(clock::time_point timer_name) {
return std::chrono::duration_cast<milliseconds>(clock::now() - timer_name).count() / 1000.0;
}
void stop_script() {
double secs = get_timer_seconds(start_runtime); // <=== Error (active) E0020 identifier "start_runtime" is undefined
MessageBox::Show(System::Convert::ToString("runtime: " + secs), "", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
}
Is there a way to make the time point created in a private function to be available in other functions without using a separate thread?
Thanks
Try something like this:
private:
clock::time_point& start_runtime = *new clock::time_point( );
System::Void start_Click( System::Object^ sender, System::EventArgs^ e)
{
start_runtime = clock::now( );
. . .
}
But there is a series of useful .NET classes and functions that can be used in C++/CLR.