|
As Simon has said, there is no 'shared static domain'. You will get the object from the domain running the code.
You didn't ask this, but it may be helpful: the scope of static fields is the AppDomain. So if you use a class with a static field, you will get one object per domain.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Thanks for the reply, I think I either misunderstand static or AppDomain. Is the AppDomain shared across multiple instances of the same application? (Assuming that they are running on the same machine)
____________________________________________________________
Be brave little warrior, be VERY brave
|
|
|
|
|
Adriaan Davel wrote: Is the AppDomain shared across multiple instances of the same application?
No, AppDomain is an isolation container within a process. So just as each process is separated on your machine, so each AppDomain is separated within each process.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Thanks Nick, thats what I understood. The reason why I asked the question is that static is not isolated within an application and the AppDomain is, so how does it find the correct AppDomain? Or is the how not important?
____________________________________________________________
Be brave little warrior, be VERY brave
|
|
|
|
|
Ok, my confusion was not with AppDomain but with static... I also see that static in C# is quite different to static in c++ and I think my confusion came in from my c++ background, I studied it 8 years ago but have been doing c# mostly...
Does static differ in definition in Visual Studio c++ to Borland c++ of 8 years ago?
Also I once had a web application (ASP.Net) where the static variable was shared between users (and caused major confusion), does that mean static is shared between multiple instances of a web application, but not a windows application?
____________________________________________________________
Be brave little warrior, be VERY brave
|
|
|
|
|
Adriaan Davel wrote: static in C# is quite different to static in c++
Yes
Adriaan Davel wrote: does that mean static is shared between multiple instances of a web application, but not a windows application?
ASP.NET is still a .NET framework, so static works the same way. However in ASP.NET you can have many threads in an AppDomain that are each serving a request, so they will all see the same static instance.
I found this[^] on Google books. Might help - starts on p.571
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
give me some ideas abt HTML,,,,,i need a code for design a simple page,,tht must have a login form and hyperlink for next page also,,,send the code r any course material as sson as possible frnds....bye ..
|
|
|
|
|
That's not the way this site works - you should search around Code Project for beginners articles on website design. Hover over the Articles link (between Home and Message Boards in the menu) and select Beginners Articles[^].
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
SqlConnection con = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=MLM;Integrated Security=True");
con.Open();
SqlCommand com = new SqlCommand("select Pin_Password from RegistrationForm where Pin_Password = '" + TextBox3.Text + "'", con);
SqlDataReader rs = com.ExecuteReader();
DataSet ds = new DataSet();
while (rs.Read())
{
if (rs["Pin_Password"].ToString().Trim().Equals(TextBox3.Text.Trim()))
{
DateTime dtStart;
DateTime.TryParse(TextBox1.Text, out dtStart);
DateTime dtEnd;
DateTime.TryParse(TextBox1.Text, out dtEnd);
SqlDataAdapter adp = new SqlDataAdapter("select RequestedDate,RequestedPins,ApprovedPins,Action from AdminPins where RequestedDate between '" + dtStart + "' and '" + dtEnd + "'", con);
adp.Fill(ds);//It is giving error at this place
ds.Clear();
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
else
{
Response.Write("Enter Correct Password");
}
}
rs.Close();
com.ExecuteNonQuery();
con.Close();
|
|
|
|
|
You are getting an error here because you have an active operation being performed on this connection, i.e. you are already performing a DataReader operation when you attempt to perform the fill. Your Fill operation needs to operate on a different connection, or you need to enable MARS (Multiple Active Result Sets) on your connection.
BTW - your application should be rewritten to cope with SQL Injection Attacks. You have a very vulnerable design here.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I have a config file in xml format which specifies where in the Windows registry to look for the location of my appliation. For example, the xml would specify "HKEY_LOCAL_MACHINE\SOFTWARE\MyTestApp\InstallDir".
If haven't yet created the MyTestApp key in the registry and the below line of code is executed, I get "Object reference not set to an instance of an object" exception.
String filePath =(string) Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\MyTestApp", "InstallDir", "");
I know I could test for the existence of the RegistryKey first(see below code) but I don't want to hardcode this to the LocalMachine hive. Is there a way to get to the registry hive by name?
RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\MyTestApp");
|
|
|
|
|
You're getting the exception because Registry.GetValue returns null if the key doesn't exist, and you are casting this null to a string. Instead you should check for null first.
Object keyValue = Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\MyTestApp", "InstallDir", "");
String filePath;
if(keyValue != null)
{
filePath =(string)keyValue;
}
else
{
}
(By the way, the registry is best avoided now for most stuff. You should consider looking at .net settings or isolated storage instead unless you have to support the registry for backwards compatibility or something like that)
Simon
|
|
|
|
|
Simon Stevens wrote: // Now you know you have a value, so you can cast it to a string.
Not necessarily. You may have a non-null string object but still not have a value, i.e. an empty string. A better approach may be to use String.IsNullOrEmpty
only two letters away from being an asset
|
|
|
|
|
I see your point, and normally I would recommend using .isNullOrEmpty, but in this case the data retrived from the registry is an Object . The check for null is to find out if a non-null value was returned from the registry. If the object is non-null (including empty string) (and assuming that you created the key, so you know that the registry data type is a String type), then you can cast it to a String . Then, you can do String.IsNullOrEmpty to see if the registry value is an empty string if you want, but the point is that the registry key existed, and you have data, even if it's an empty string.
(I suppose, depending how critical the app is, you might want to do a non-failing cast instead just incase someone has changed the registry data type, but this is going a bit beyond the scope of the OP now)
Simon
|
|
|
|
|
Thank you everyone. Checking for null solves my problem.
|
|
|
|
|
Hi fellows,
I´m using the class "BaseEntityWithState" as the base class for lot of aur bussines classes.
Basically it has lots of methods to trak object state (stripped off so only relevanto ones to the problem are shown).
When a child class has one of its porperties modified it changes the state to "modified".
I need to clone the entity and I´m doing that serializing and deserializing the instance.
Supouse I need to clone a child entity wich currentStatus is "unchanges". During the deserialization part of the cloning method, the members of the base class are assigned it´s values properly. Then whe the "Value" property of the child class is set, it changes the currentStatus property of the base class. So the original instance has currentStatus "unchanged" and the cloned one has "modified".
What I need is to be able to avoid that.
I tried setting the Order property of XMLElement atributte to change the serialization order, but the serializer complains that I should specify order for all member of the base an child class. This would be to hard to mantain. Remember there are lots of child classes, each one with several members.
So, the only solution that is working is declaring in the child class, after all other declarations a "currentStatus2" property (commented in the code).
That way this is the last property to get serialized and also the las to get deserialized, propperly setting the currentStatus atributte to the original value.
For this solution to work requires me to add the ficticious property to EVERY child class. Not too much work, but I´m worried that this is not a good solution, cause it requiere other programmers (less techies than me) not to forget to add that property.
I´d like to provide a better solution to this problem.
Thanks in advance
Sebastián Streiger
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Reflection
Public Enum estados
unchanged
modified
End Enum
Public Class BaseEntityWithState
Private Shared Function getXmlTypeMapping(ByVal tipo As System.Type) As XmlTypeMapping
Return (New XmlReflectionImporter).ImportTypeMapping(tipo)
End Function
Public Function serialize() As String
Dim writer As New StringWriter
With New XmlSerializer(Me.GetType())
.Serialize(writer, Me)
End With
Return writer.ToString
End Function
Private Shared Function getXmlSerializer(ByVal tipo As System.Type) As XmlSerializer
Return New XmlSerializer(getXmlTypeMapping(tipo))
End Function
Public Function DesSerializar(ByVal tipo As System.Type, ByVal xml As String) As Object
Return New XmlSerializer(tipo).Deserialize(New StringReader(xml))
End Function
Public Function clone() As BaseEntityWithState
Dim aux As BaseEntityWithState = Me.DesSerializar(Me.GetType(), Me.serialize)
Return aux
End Function
Private status As estados = estados.unchanged
Public Property currentStatus() As estados
Get
Return Me.status
End Get
Set(ByVal value As estados)
Me.status = value
End Set
End Property
End Class
Public Class childEntityWithState
Inherits BaseEntityWithState
Private _value As Integer
Public Property value() As Integer
Get
Return Me._value
End Get
Set(ByVal value As Integer)
Me._value = value
Me.currentStatus = estados.modified
End Set
End Property
'Public Property currentStatus2() As estados
' Get
' Return MyBase.currentStatus
' End Get
' Set(ByVal value As estados)
' MyBase.currentStatus = value
' End Set
'End Property
End Class
|
|
|
|
|
What I'm about to propose is not good design, but it may be a simple solution: use a private boolean to inhibit changing the status property while deserializing.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
modified on Wednesday, June 3, 2009 8:22 AM
|
|
|
|
|
Moreno:
How could I realize during property assigment if it´s being done by serialization or by a line of programmer code.
I don´t think it´s good design also, but I don´t know if it´s possible.
Keep in mind that this class can be serialized within other classes serializacion, so I can´t make something like:
original.TrackStatus = false
cloned = original.clone
original.TrackStatus = true
cloned.TrackStatus = true
Anyway, thank you very much
Sebastián Streiger
|
|
|
|
|
Just pretend I didn't post anything ok ? What I said up to now is just too stupid haha.
But really, I couldn't come up with any serious way to do what you need. Tweaking the DesSerializar or Clone routines is sure the right way to go, but I can't come up with a good way of storing the serialized object's status and then pasting that into the deserialized object.
Hope some good guy here will offer a good solution.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Moreno:
He, He,
I also hope we can get a clean solution to this problem.
Your feedback is highy appreciated.
If I manage to find a bettter way I´ll let you know.
Thank you very much.
Sebastián
|
|
|
|
|
Hummm I either was too dumb yesterday or I'm missing something now.
I think what you need is simply:
Public Function clone() As BaseEntityWithState
Dim statusbuffer As estados = Me.status
Dim aux As BaseEntityWithState = Me.DesSerializar(Me.GetType(), Me.serialize)
aux.status = statusbuffer
Return aux
End Function
Hope this time it's useful to you.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Moreno:
Is that your Name?
What you suggest is the first thing I tried, but It only worked with the object that is getting called clone.
It doesnt work if that object contains references to other chils of the same base class. I mean, it works for the object being cloned, but not for the references it has.
I´m working now in a solution suggested by a collegue by implementing the IXMLSerializable interface.
I´ll let you know what comes up.
Sebastián
|
|
|
|
|
Yep it's my name, I know it's a common family name for Spanish and latinos.
It sure works only for the object on which you call clone, and not for references.
Best of luck with implementing the interface then.
At first I also reasoned on the line of parsing the XML and getting the status directly from there, in order to apply it to the cloned object(s) after de-serialization, but I find it too much of a patchy solution.
Well, best of luck again, and I'll be waiting to hear how it goes.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Hi
I have a problem. I am developing a VoIP application using DirectSound to capture and play voice. Everything is OK with the capturing, but I can't play the received data smoothly when it is a small piece. It should be small for preventing latency. Currently I capture 320 bytes and send it via UDP. The wave format is 8000 Hz and 8000 B/S.
For reproducing the problem I use the following code:
int step = 320, c = 0, N = 2;
offset = data.Length % step;
// (SecondaryBuffer) buf size is N * step;
buf.Play(0, BufferPlayFlags.Looping);
byte[] smallArr = new byte[step];
double sleep = (double)step / waveFormat.AverageBytesPerSecond * 1000;
//data is a captured sound saved to a file previously
while (data.Length > offset)
{
buf.SetCurrentPosition(((c + 1) % N) * step);
Array.Copy(data, offset, smallArr, 0, step);
buf.Write(c*step, smallArr, LockFlag.None);
Thread.Sleep((int)sleep);
offset += step;
c++;
c%=N;
}
While debugging I found out that the PlayPosition cursor doesn't reach the expected point. I move it forward and the result is that not all data is played and the sound is not smooth.
There is no problem when the playing portion is bigger but I can't afford latency.
When I use a lot higher quality(and play bigger portion of data) there is no problem again but the traffic is large!
I can't use more than one buffers because the noise is awful when play/stop/mute.
So, would you help me to solve the problem with the playing buffer?
Thank you in advance!
|
|
|
|
|
Andrey U wrote: While debugging I found out that the PlayPosition cursor doesn't reach the expected point. I move it forward and the result is that not all data is played and the sound is not smooth.
That's not a good idea. Any change to the play position will affect the output. The results from GetCurrentPosition may be incorrect / inaccurate due to the way DirectSound works (especially on XP).
Your basic idea of double buffering is good, but you need to manage it in a more reliable way. The "Sleep" in particular, since it's the same length as the time to play one buffer-full, doesn't allow any time for the data copying. (You should also try to only have one copy / write for efficiency.)
My approach is similar, but I check when the play cursor switches from one buffer to the next (either half way along the double buffer, or looping back to the start) and then I copy into the other half. Use a smaller sleep time, and check regularly.
I should say "my approach was similar..." though, as I've now switched over to using XAudio2, which is much better for managing streaming.
Andrey U wrote: I can't use more than one buffers because the noise is awful when play/stop/mute.
That shouldn't happen - it sounds like something else is going wrong in that case.
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|