|
replacing lock-test by test-lock-test is a typical pattern to avoid the lock most of the time.
volatile is required to avoid the second test to rely on stale data kept around from the first test.
Bernhard Hiller wrote: But volatile costs a lot of performance
No it does not. All it does is say: go fetch that variable again, don't use a local copy you happen to have around, use the real thing. There is no system call involved, no lock mechanism, nothing. It is just referencing the intended class member.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thanks a lot for this information. I guess I will use that pattern more often in future.
|
|
|
|
|
you're welcome.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Something I've only played around with out of curiosity and never seriously used, so a question really (there could be a good reason it is a bad idea)
Isn't this situation, the deferred creation of _Bernies, what Lazy<T> is for?
private Lazy<List<Bernie>> _bernies = new Lazy<List<Bernie>>(System.Threading.LazyThreadSafetyMode.PublicationOnly);
public List<Bernie> Bernies {
get
{
return _bernies.Value;
}
}
|
|
|
|
|
This is a method to defer initialization however in the op's case he needs to control initialization by more than one object, not just lazily.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Yeah, as I said I am not sure.
BTW, I was thinking the Lazy<T> constructor that has a delegate parameter for initialising the array. I must be wrong, or am completely misreading what the OP was trying to do. Which I thought was to guarantee thread-safety when the property is being accessed during instantiation of the array.
I think I am misreading it all.
Cheers
|
|
|
|
|
That's a new feature of .NET 4. Already its name implies that it was made for me (I am really lazy), hence I should upgrade to .NET 4 soon.
|
|
|
|
|
Smile. Yeah, it may be a lazy way indeed, which is probably why I was sounding hopeful!
|
|
|
|
|
---------------------------
Error
---------------------------
Fatal Execution Engine Error (0x7927f26e)
---------------------------
OK
---------------------------
pls help resolve this error.
Thanks inadvance..
No Defeat Is Final Until You Stop Trying!.......
|
|
|
|
|
This error is normally the result of a corruption of your .NET installation. I'm afraid it means that you are going to have to reinstall .NET. BTW, I found this with a quick Google of the exception you typed in. You could have found the answer quicker than it took you to type your question. Why did you not use Google first?
|
|
|
|
|
I hav googled it already bt nothing resolved my problem.
i hav reinstalled my .net framework still the problem persists.
so i thought of posting here if somebody facing the same issue can help resolve.
No Defeat Is Final Until You Stop Trying!.......
|
|
|
|
|
Are you running multiple versions of .NET on your machine? It could be that the app is targetting a different version of the runtime to the one you think it is. A way to test this is to create a virtual machine with an installation of the framework that you think it's targetting, and attempt to run the application in this VM. Then, if it still fails, create a simple console application that definitely targets that version. If you the console app works, then you pretty much know that either your whole application is hosed, or it's a different version of the framework that it should be running.
One thing you could do, is try to load your assembly from a different .NET application using the Assembly load methods and see if it throws a BadImageFormatException which can occur if your application is either not a .NET assembly, or is internally corrupted.
Beyond that, the corruption could be because you are relying on a component that uses a different version of the .NET framework to the one you reloaded, and that framework is corrupt.
|
|
|
|
|
thank you for the valuable suggetions..
i'll check all the cases
No Defeat Is Final Until You Stop Trying!.......
|
|
|
|
|
Good luck. I hate exceptions like this.
|
|
|
|
|
I think Microsoft .Net files were screwed up. failed to use Control Panel to get rid of them. Able to download Microsoft .Net V2.0 for install, but just did a repair .
|
|
|
|
|
Could the subject be any more clear?
Especially when writing your own Generic classes.
I kind of know how they work (little experience).
For example, would the following be acceptable?
Public Interface ISomething(As T)
Function Something As T
End Interface
Public Class SomethingElse(As T)
Public Property SomeStuff As T
End Class
Or is that just not best practice?
I know some of the benefits, like no (un)boxing of Objects (thus fater performance and less chance on wrong casts?).
What are the drawbacks?
Edit:
And of course when to (not) use Generics
It's an OO world.
|
|
|
|
|
Generics can be very useful. I believe the complier actually creates the classes based on the type so you end up with multiple versions of the same class - one for each (or each combination of types if using <T, V> etc). This I suppose could lead to bloat if there are lots of different T s in your code, but there would have to be a lot! If you used object then there would only ever be one type of the class.
I'm not fond of auto properties as there is no oportunity for validation in the setter or event raising.
|
|
|
|
|
Not sure what you mean, but if you mean that the following...
Public Class Something(Of T1, T2)
Public Function GetSomething(ByVal var As T1) As T2
End Function
End Class
Public Class Form1
Private _field As Something(Of SomeClass, SomeOtherClass)
Sub Me_Load(...) Handles Me.Load
_field = New Something(Of SomeClass, SomeOtherClass)
Dim var As SomeOtherClass = _field.GetSomething(New SomeClass)
End Sub
End Class
...creates a couple of versions of SomeClass and SomeOtherClass I think you are wrong.
Actually I think the only instances of SomeClass and SomeOtherClass are the Class I pass to the Function and the Class that it returns (var ). And of course I have an instance of the Something(Of T1, T2) Class .
Correct me if I am wrong
When there is no need for validation or event raising a non-auto property creates a lot of overhead
It's an OO world.
|
|
|
|
|
Naerling wrote: couple of versions of SomeClass and SomeOtherClass I
think you are wrong
I will need to check (maybe over the weekend) but I'm sure I remember reading this on MSDN or somewhere similar.
Naerling wrote: When there is no need for validation or event raising a non-auto property
creates a lot of overhead
Not true, the backing field is created invisibly for you in the IL, these are identical to all intents and purposes (C#):
public T SomeData
{
get; set;
}
private T someData
public T SomeData
{
get { return someData; }
set {someData = value; }
}
|
|
|
|
|
With overhead I meant extra code to write and dirty your screen
Thanks for pointing it out though.
DaveyM69 wrote: but I'm sure I remember reading this on MSDN or somewhere similar
I would like to read that too
It's an OO world.
|
|
|
|
|
|
Thanks for the link. It shows even code gets instantiated!
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thanks for the link!
I think I misunderstood your earlier post after reading this.
And it never actually occured to me that value and reference types would work differently (well Rob already explained it pretty well too).
This article clears some things up though.
It's an OO world.
|
|
|
|
|
If I recall correctly, the behaviour is as follows:
When the run-time loads a generic class, it does create multiple versions, but not as many as you may think.
Consider...
Public Class Pair(Of T1, T2) ' I detest the generic syntax for VB, C#'s <T1, T2> is so much clearer
Public First As T1
Public Second As T2
End Class
For T1, the compiler must generate a version of each value type (derived from System.Value, such as Int16, Int32, ...) because the representation of the object varies - some value types may be larger than the size of an object reference.
However, where T1 is an Object type, the variation can be omitted, as the representation remains constant.
Similarly for T2.
So for Pair(int, char) is one type, Pair(int, Person) is one, but Pair(int, object) can share the representation of Pair(int, Person). Obviously Pair(object, int) is another axis of variation, but there tend to be reasonable bounds to the amount that occur in practise.
|
|
|
|
|
I am trying to retrieve a value within a textbox that has a vlue already passed to it within a webpage. As you can see I am trying to extract the last name here(red fire truck:
<span id="CallerForm1_CallerInformation1_lblLNameLabel" class="clsFormLabelSide" style="font-size:XX-Small;z-index: 109; left: 273px; position: absolute;
top: 56px">(last)</span>
<input name="CallerForm1:CallerInformation1:txtLName" type="text" value="RedFireTruck" maxlength="50" id="CallerForm1_CallerInformation1_txtLName" style="width:168px;z-index: 105; left: 266px; position: absolute;
top: 72px" />
What I have been using is the chunk within the methos: Document Completed. Im trying to store its value in a variable so I can pass the var to the next screen or a different page. All I could come up with was this. keep in mind I am using a msgbox to see if anything has been saved or retrieved by so far I havent gotten any notifications:
Dim theElementCollection As HtmlElementCollection = wbCHCTrac.Document.GetElementsByTagName("input")
If wbCHCTrac.Url.ToString.Contains("client/upd_caller.aspx?") Then
For Each currentElement As HtmlElement In theElementCollection
Dim controlName As String = currentElement.GetAttribute("id").ToString
If controlName = "CallerForm1:CallerInformation1:txtLName" Then
MsgBox(currentElement.GetAttribute("Value").ToString)
End If
Next
End If
Any help would be appreciated =)
|
|
|
|