|
Hi,
i would like to load a singleton class in my default app domain. But also create a new domain and use the same class type with a new instance/singleton.
How to do that?
.:[Greetz from Jerry Maguire]:.
|
|
|
|
|
This shouldn't be a problem. Locking against types to create singletons (as is common for determine if an instance already exists) is supposed to be context-bound. Being that the AppDomain is a separate context, this shouldn't pose a problem.
The following code fragment (that works) should prove it:
using System;
using System.IO;
using System.Reflection;
public class Test
{
public static void Main(string[] args)
{
Singleton.SayHello();
Singleton.SayHello();
if (!Singleton.Foo)
{
Console.WriteLine("Executing entry point in same AppDomain...");
AppDomain.CurrentDomain.ExecuteAssembly(
Assembly.GetEntryAssembly().Location);
}
if (AppDomain.CurrentDomain.FriendlyName != "New")
{
Console.WriteLine("Creating new AppDomain...");
AppDomain domain = AppDomain.CreateDomain("New",
AppDomain.CurrentDomain.Evidence);
domain.ExecuteAssembly(Assembly.GetEntryAssembly().Location);
}
}
}
public class Singleton
{
private TextWriter writer;
private Singleton()
{
Console.WriteLine("Creating new singleton instance...");
writer = Console.Out;
}
private static Singleton instance;
private static Singleton Instance
{
get
{
if (instance == null)
lock (typeof(Singleton))
if (instance == null)
instance = new Singleton();
return instance;
}
}
public static void SayHello()
{
Instance.writer.WriteLine("Hello, world!");
}
private bool foo = false;
public static bool Foo
{
get
{
if (!Instance.foo)
{
Instance.foo = true;
return false;
}
return true;
}
}
}
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi Heath,
thank you for your sample code.
Let's say i've got a WindowsApplication project. Than i have a class library project which defines the type with the singleton.
Now my WindowsApplication project references the class library assembly for "normal" use of singleton type.
Now i would like to create a new appdomain and create a new instance of my singleton class.
How to do that? The other "normal" instance is alive in the CurrentAppDomain.
.:[Greetz from Jerry Maguire]:.
|
|
|
|
|
You'll need to have an assembly with an entry point. Have another EXE assembly that also depends upon your singleton and forces it to create an instance of itself. In my sample, this was the same executable. Just make another executable that doesn't load your win app - just the singleton.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
hi,
i want to know any class in .net able to convert a byte array (eg. 4 bytes) into a 32-bytes floating point data?
if not, i need to handle by myself with bitrise operation.
any help?
thanks,
jim
|
|
|
|
|
BitConverter.ToSingle .
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi,
I want to be able to give read/write permissions on certain AD classes to certain accounts.
For instance, I want an account (say user1) to be able to create serviceConnectionPoint child objects. Another example would be to grant an account write access to mS-SQL-SQLServer class.
Any ideas how to do this in C#?
Thanks in advance.
Nidhi
|
|
|
|
|
You can access security only via Interop of adsi32 i think. There is no file security for .NET. I think there is a port in gotdotnet somewhere but you need to fell brave to put that under production. How would you be using mS-SQL-SQLServer?
Cheers,
Erick
|
|
|
|
|
Yes, I can use ADSI interop, but how do I set permissions on a class?
I shall be pulishing some application specific info in the keywords property of mS-SQL-SQLServer.
Regards,
Nidhi
|
|
|
|
|
I'm having a wierd issue where i run a query in a thread and the while(Connection.read()) duplicates my results. Anyone else have this issue? For isntance if I have TestTable with the following values:
TestID
1
2
3
It will console.writeline
1
1
2
2
3
3
Below is sample code:
private void button3_Click(object sender, System.EventArgs e)
{
ThreadStart DBThread = new ThreadStart(StartDBDelegate) ;
Thread DB = new Thread(DBThread) ;
DB.Start();
}
public void StartDBDelegate)()
{
Invoke(new UpdateLoadTableDelegate(RunUpdateNow));
}
public void RunUpdateNow()
{
string source =
"server=testserver;uid=testuid;pwd=testpassword;database=TestDB";
string selectconn1 = "SELECT TestID as dbTestID FROM TestTable"
SqlConnection conn1 = new SqlConnection(source);
conn1.Open();
SqlCommand executeconn1 = new SqlCommand(selectconn1,conn1);
SqlDataReader Connection1 = executeconn1.ExecuteReader();
while(Connection1.Read())
{
Console.WriteLine (Connection1[0].ToString())
}
}
I can reduce this menace by doing the following to the while loop, although I shouldnt have to do this...this is really bugging me. It doesnt do this outside of the thread.
string strTestID = "";
while(Connection1.Read())
{
if(strTestID != Connection1[0].ToString()))
{
Console.WriteLine (Connection1[0].ToString())
strTestID = Connection1[0].ToString());
}
}
|
|
|
|
|
I am currently trying to learn C# and looking at some of the classes available, I have come across a snag. I'm looking at the TimeZone class in the System namespace. It has a static function CurrentTimeZone which is fine, but what if i want to work with a different TimeZone? How do I specify that I wish to work in US Mountain Standard Time or AUS Eastern Standard Time ?
Thanx in advance.
The jubjub
|
|
|
|
|
Through the system clock. This isn't really meant to be changed, but is to help with UTC conversions. The date/time related stuff you should be looking at is the DateTime and TimeSpan structures. Using different combinations of methods and properties between all the date/time-related classes allows you to get offsets, manipulate dates and times, and much more. There's a lot available.
As far as working in different dates and times (like for applications), it must either be set by the operating system or emulated through assuming a different offset (like to display a world clock or something). Just remember to work with UTC and not local dates and times, because some time zones don't recognize daylight savings time (I want to move there!). The TimeZone class is there to help you figure all that stuff out without coding most of it yourself.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanx Heath, I was hoping there was something I was missing, like some fancy function or hidden class that would make my life easier so I wouldn't have to do too many calculations. But, to the calculations I go.
I did these sorts of calcs in C++ a while back, by getting the timezone info from the registry, and i was thinking maybe MS has made my life a little easier with .Net.
Thanx for your help buddy.
Jubjub
|
|
|
|
|
Sometimes it's a question of whether it should be allowed. Such time zone assumptions could lead to problems.
Also, here's a good / important tip: much of the stuff in .NET (especially for Windows Forms) is actually their Win32 counterparts wrapped in .NET classes. System.Windows.Forms for example, redefines a LOT of structures and constants found in various headers (especially for common controls) and P/Invokes a lot of methods (countless variations of SendMessage , for example).
So, while classes in a truly object-oriented framework might make things easier by the sheer nature of OO, the functionality isn't a whole lot different (just easier to do: ex. write a C++ COM component and .NET component exposing a CCW and see which one takes less coding and is less prone to coding errors!).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
This is my first .net web application. I am using asp.net and C#. I have a db lookup that I want a progress bar or cursor change to show the end user the program is loading. I have found many things for the "Web.Form" side but none for the "Web.UI" side. Any suggestions or links?
Thanks,
John
|
|
|
|
|
Actually, this really isn't the place to post this. You'll want the Web Development forum. But anyway...
ASP.NET is server-side technology. In order to display a progress bar, this is all done through client-side scripting. To display a different cursor, see the cursor attribute of CSS. It allows you to set a predefined cursor (like the wait cursor) or to use a custom one (through a url('/path/to/my/cursor.cur') value).
As far as a progress bar, this is either very easy or very hard. To just display some eye candy, you can easily use javascript to resize an image by a certain amount based on a timer. If that amount is to mean anything real, you have to ask the server for status. Perhaps this can be acheived through some nifty use of HTTP Keep-Alive, but I've never seen it. Only other ways are to use ActiveX (IE-specific, Java Applets, or embedded .NET user controls (IE 5.01+ specific) to either display the progress bar or poll the status on the server based on the current user's context and update the resizing image ("progress bar").
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Alright,
My first born child to anyone who can sort me out. I have an ArrayList filled with objects called remotes. Remote is a struct, and in remote I wrote the CompareTo method to allow a binary search on the arraylist. This CompareTo method compares the remoteIDs, which is a field that I fill in as I populate the arraylist. The remoteID is from a database, it is unique, but not necessarily consecutive. So I may have three remotes in my arraylist of 30, 50, and 80. When I do a binary seach based on an object I populate, say I create a new remote, set its remoteID to 30, and do a binary seach on the arraylist, it works if the remoteID is close to the bounds of the array. So if the array length is 82, and my remote ID is 50, it finds the object and returns the index correctly. When I start getting nearer to the bounds of the array, say remote id equals 81, or even 85, being greater than the bounds of the array, it returns a negative number being one greater than the count of the array. So in this case a -83. Is it using the bounds of the array as min and max numbers, and therefore the algorithim bombs out do to the fact that my RemoteID numbers are outside those bounds? What can I do to resolve this issue? Any help offered would be greatly appreciated.
Thanks,
Ryan
|
|
|
|
|
I'm not quite sure I follow you right (I hate "run-on" paragraphs ) so let me ask a couple things. So, you implemented IComparable for sorting, right? This problem occurs when sorting? How about posting the source somewhere (if not long, just post it here)?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
No, I implemented IComparible for the binary search function. The code is pretty involved, so if i posted it, i think it would make things difficult.
|
|
|
|
|
AFAIK you will need to call sort everytime u insert a new element. BinarySearch only works on sorted data.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Echoing leppie, the only way you can perform a binary search is if the elements are ordered. Otherwise, there's no way to partition the search space.
Binary search algo:
1. initial searchpos = midpoint of array
2. testvalue = value(searchpos)
3. if( testvalue > searchvalue )
searchpos = midpoint( beginningofarray, searchpos )
elseif( testvalue < searchvalue )
searchpos = midpoint( searchpos, endofarray)
else
you found your value
4. goto 2
[EDIT]Yeah, I'm aware of the glaring bugs in the above pseudocode...see below for explanation [/EDIT]
Not sure if this answers anything...I'm too burnt out to tell
Jeremy Kimball
|
|
|
|
|
|
Helo,
I'm developing a web page which need an ActiveX control,
I add the ActiveX control to the webform, and then I go to
the properties of the new object and put ID = Objeto1,
then I try to write in the webform Objeto1. nothing apear,
but i wrhite Objeto1.Method(); and when i try to compile
send me an error.
How I can add property the ActiveX control?. I need the
methods, properties and events of the ActiveX.
Levi
|
|
|
|
|
Are you wanting to add this as a server-side object (for data processing, etc.) or so the client (browser) sees it? If the latter is the case, you don't do anything on the server side. Embed it on the web page and rely upon client-side scripting like Javascript and VBScript. These are two distinct contexts that must be understood. The server processes the page which produces HTML. That HTML is downloaded to the client to display. Everything you see in a browser is resident in memory on the client.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
How Can we process a html document in windows application and display a html document in windows application
Thanx
Inam
|
|
|
|