|
1. About deinit()- if that's what you want, fine. It's just that to me it seems to just bring extra complexity - but hey, it's your code
2. Yes, it's thread-safe
Best,
John
|
|
|
|
|
Is it also thread safe if I remove isInited checks from X1 and X2 getters? - Granted no one calls any methods of this class, unless a init method is called (this I can ensure because I am using this class directly) - I have isInited check first in any method calling this class.
|
|
|
|
|
1. Yes it is - variables X1/X2 are automatically initialized to zero.
2. You modified your code:
public static int X1()
{
if(!isInited()) throw new Exception("init first");
return x1;
}
should be
public static int X1()
{
lock(this) {
if(!isInited()) throw new Exception("init first");
return x1;
}
}
Best,
John
|
|
|
|
|
Yeah but I said what if I do
public static int X1()
{
return x1;
}
Granted none calls these methods before INIT method is called (I can ensure this because I am writing those methods) - I will check isInited calls in the start of each method calling this class
|
|
|
|
|
No, that is not thread-safe. This is :
public static int X1{} { lock(locker) return x1; }
Best,
John
|
|
|
|
|
|
|
Thanks a lot, few more questions, and I would appreciate if you can help:
- if I add more variables other than x1 and x2 but I maintain same style in accessing and initializing them will it affect thread safety? will it affect performance? (probably). Do you know more performance friendly way to solve the problem my class solves?
|
|
|
|
|
1. if you add more variables in the same manner, yes
2. will it affect performance? don't worry about that, performance will be the same. And on the init()/deinit() - the "decrease" won't be noticeable.
3. Your class is fine
Best,
John
|
|
|
|
|
Thanks a lot!!!
So you are saying if I add more properties in same manner, it won't be problem?
|
|
|
|
|
Yup, that's exactly what I'm saying
Best,
John
|
|
|
|
|
|
you're welcome
Best,
John
|
|
|
|
|
Great job supporting this OP, John. I am voting your replies up. cheers, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Thanks
|
|
|
|
|
I am voting your replies up.
me too
|
|
|
|
|
granted anyone using Parameters class WILL first check if it was inited or not using getter
|
|
|
|
|
does requirement to have public deinit make harder to make this class thread safe?
|
|
|
|
|
Hi,
I am having a Windows Ui for placing some text in Unighraphics-
So the problem is when i place a text i get "work in process" dialog(which is of Unigraphics), I want to close this but it doesnt,when i close the windows UI this dialog vanishes.
I want Windows ui but i dont want "work in process" dialog.
when i check task manager, i can see two applications , but both say same process in task manager ugraf.exe.
Please help I am using c#
|
|
|
|
|
|
Please do not post the same message in two forums.
If you have spent thousands of US $ to purchase Unigraphics NX from Siemens, you are certainly entitled to tech support from them.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
You're not going to get an answer to this question because you haven't conveyed any context information what-so-ever. We have no idea what you're doing, how you're doing it, what the code looks like and you haven't even provided a problem description that makes any sense.
Seriously, if you can't describe the problem you're trying to solve to us in sufficient detail, you have no hope of describing the solution to a computer.
|
|
|
|
|
I have C++ code which has calls like this
1) SystemTimeToFileTime(&st, &m_Time)
Before above call st is assembled by assigning values to its members manually - but only year, month, day, hour, minutes and seconds are assigned to it.
m_Time is instance variable of type FILETIME.
Afterwards there is a function like that:
2) dppDatetime_t RsDateTime::GetAsPrepaidTime() const
{
dppDatetime_t dt;
SYSTEMTIME st = GetLocalTimeAsSystem();
dt.Year = st.wYear;
dt.Month = st.wMonth;
dt.Day = st.wDay;
dt.Hour = st.wHour;
dt.Minute = st.wMinute;
dt.Second = st.wSecond;
return dt;
}
GetLocalTimeAsSystem defined as:
3) SYSTEMTIME RsDateTime::GetLocalTimeAsSystem() const
{
SYSTEMTIME st;
::FileTimeToSystemTime(&m_Time, &st);
return st;
}
I basically need to replicate all this functionality I mentioned in above 1), 2), 3) points in C#. I would really appreciate some help on how to go with this? How to achieve same result in C#?
Can't I implement what is done above using only DateTime structure in C#?
modified 30-Oct-15 4:46am.
|
|
|
|
|
I really don't understand what you want. C++ has a lot of ugly structures for dealing with time, and in c# you don't have to care - you have the very-easy-to-use DateTime class.
For getting the current time, just use
DateTime.Now
DateTime.UtcNow
Best,
John
|
|
|
|
|
I want to achieve steps 1 and 2 as in the question
|
|
|
|