|
Don't take *this* the wrong way, but you need to lighten up
I was being extremely sarcastic in saying I'm older than you. (born on 5/10/77, which makes me a whopping year older than you). I was and still am in the same boat you're in now - problems dealing with "old-school" developers who don't trust your judgement, even when it's obviously right.
I had the same situation with the whole female thing in high school...it's an interesting experience trying to explain the female ovulation cycle to your girlfriend
|
|
|
|
|
public sealed class Singleton<br />
{<br />
static readonly Singleton instance=new Singleton();<br />
<br />
static Singleton()<br />
{<br />
}<br />
<br />
Singleton()<br />
{<br />
}<br />
<br />
public static Singleton GetInstance()<br />
{<br />
return instance;<br />
}<br />
}
That was from this[^] article.
Maybe you can answer this question:
Is there an explicit need there for the private constructor to avoid initialization? If we remove it completely, will .NET supply a default public parameterless constructor?
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
The point of making a constructor private/protected is so that someone using the object via the API can't create an instance on their own. This is very handy if you want to make an object with singleton behavior.
The only way you get the instance (the only instance) is using GetInstance . Doing it this way, there is no other way create the object. If you leave a construtor publicly exposed then it cirumvents the code you put in place to enforce the singleton behavior.
|
|
|
|
|
Thank you that was very clarifying.
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
If you remove the private default constructor, yes, the compiler will provide one.
Also, this isn't the best singleton pattern to use. The one I posted earlier was. It uses a double-check locking approach which eliminates a couple race conditions that may occur.
This has been discussed in the past in this forum so if you want to know more, try searching for "singleton" or something for the C# forum.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Well, what I'm doing right now is, I'm providing the binary deserialization mechanism in the static constructor, since I only need to load the settings from the file once in the lifetime of the program. Then, I'm providing a Save instance method so that I could save multiple times, which is needed whenever the settings dialog is opened and closed with Ok button.
If there is nothing wrong with this in your opinion, then don't post an answer; otherwise, please comment.
Thanks!
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
There's nothing wrong with it, but what I was referring to in the previous post could result in your settings being loaded more than once. Now, this probably wouldn't be a problem, but locking your resources will gaurantee that it wouldn't.
I'm not trying to down-play your approach, only present different ideas. It's you're implementation - do what you want.
Typically in a singleton you provide static methods and properties and hide instance details from other classes. For instance, you could also have your Save method as static and it gets the private Instance property (or uses your GetInstance method) and saves the data. For the caller then, it's as simple as doing MySettings.Save .
Again, just some things to think about. Your approach would work fine in most cases (only may become a problem with multiple AppDomains in a single process, which may not apply).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi
I am using VS 2003 with the latest windoze media player.
I want to hide a video in a dll.
Then I want the media player to access it. How do I do that?
Thanks!
Antoine
This by our hands that dream,
"I shall find a way or make one!"
|
|
|
|
|
You can't, not without implementing your own native pluggable protocol handler for windows (like that which handles http(s), ms-help, its, res, etc.). Windows Media Player uses monikers to bind to streams and there is not - at this time - a plugglable protocol handler for streaming embedded resources.
Also, embedded a video in an assembly is extremely wasteful. You'll increase the load times of the assembly incredibly. Just distribute it as a separate file and point the URL property of WMP to the file when you need to play it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yeah,
OK. thanks for the answer. didn't thought about the loss of loading time.
Do you know of a way to keep the videos secure? Digital Rights Managment
seems a way to go -is it???
Cheers
Antoine
This by our hands that dream,
"I shall find a way or make one!"
|
|
|
|
|
Yes, DRM would be something to look into.
Beside, if you think storing the file as an embedded resource (or even in the .rsrc section of the PE/COFF executable itself) would keep it secure, you'd be sorely surprised. ildasm.exe, for example, can easily extract anything in an assembly. One could throw together a simple .NET app to do this as well. Resources in native DLLs can easily be extracted, too (though writing the code for it is a big harder, but plenty of apps - including Visual Studio - can make quick and easy work of that by just loading the .rsrc section and providing extraction capabilities).
If you did want to embed it stil, you'd have to extract it anyway in order for WMP to play it. At that point someone could also mess with it.
DRM is really about your only protection, if it is really that necessary.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the input! Ok So the request forms are all sent out.
I just I wont need to shell out money by the windows.
Cheers
Antoine
This by our hands that dream,
"I shall find a way or make one!"
|
|
|
|
|
Lookup MSDN and Google with "res://"
|
|
|
|
|
Can anyone tell me how to get a list of data types.
I'm trying to fill a combobox with data types, such as string, int, long, etc., and am wondering how I can enumerate whatever enum that holds those.
And in asking that question, a better one would be how do you enumerate any enum and pull out a string representation of the members.
Something like this... maybe...
public enum Colors
{ red, green, blue }
foreach(string color in Colors)
{
...color.ToString();
}
|
|
|
|
|
Have a look at the Enum class (system namespace) -- GetNames and GetValues should help.
--Chris
|
|
|
|
|
|
Hi !
I need to know when my axWebBrowser finished the navigation to the web page. I hooked to .DoumentComplete event but it turns out that this event happens more than 1 time !?? (Why ?)
So - how I can tell when the web page is completly loaded ??
"I have not failed.
I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)
|
|
|
|
|
See http://support.microsoft.com/support/kb/articles/q180/3/66.asp[^] for an explanation and a workaround.
Basically, DocumentComplete is fired multiple times when a page contains references to multiple documents (i.e., frames). The easiest way is to is to see if the pDisp field of the DWebBrowserEvents2_DocumentCompleteEvent is the same reference as your AxWebBrowser instance. That'll signify that the top-level frame document has been loaded.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
In a page with Frames, there are multiple web pages being used to render one visible page. There is a frames page that describes the layout of the view panes, then there is a seperate page for each of those panes. DocumentComplete will fire for every one of those pages that is downloaded, not just the frames page.
You can use the uRL property of the eventargs to compare to the URL you sent the browser to. If the page has frames, the last URL to be returned will be the one you originally sent the browser to:
Private Sub AxWebBrowser1_DocumentComplete( _
ByVal sender As Object, _
ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent) _
Handles AxWebBrowser1.DocumentComplete
If AxWebBrowser1.LocationURL = e.uRL Then
MsgBox("Document Complete!")
Else
Debug.WriteLine("DocumentComplete received for URL: " & e.uRL)
End If
End Sub
RageInTheMachine9532
|
|
|
|
|
You copied and pasted VB.NET code from the MS KB into a C# forum? You should be punished.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
"Get the whips and chains! Bind the heathen!"
|
|
|
|
|
Yes and No...
Yes, I pasted VB code into the C# Forum. AAAAAAAhhhhhh! My mistake! I should be flogged.
It's not the exact code from the MS KB. I found that the code in the KB was for VB6 and didn't translate very well to VB.NET. The .Object property wouldn't compile. So I changed it to use the URL properties instead. It can be fooled by a redirection in the original page, but that's shouldn't be too much of a concern.
RageInTheMachine9532
|
|
|
|
|
|
Whoops! How about a C# version...
private void AxWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
if (AxWebBrowser1.LocationURL == e.uRL)
{
MsgBox("Document Complete!");
}
else
{
Degbug.WriteLine("DocumentComplete received for URL: " + e.uRL);
}
}
My DEEPEST appologies to the C# community!
RageInTheMachine9532
|
|
|
|
|
Okay, okay. Let me stitch you back up.
Microsoft MVP, Visual C#
My Articles
|
|
|
|