|
You cannot pass parameters to thread methods in .NET 1.1. There are several workarounds to solve these issues, the one we follow is
<br />
class MyClass<br />
{<br />
private int a;<br />
public int A<br />
{<br />
get{ return a;}<br />
set{a = value;}<br />
} <br />
void show()<br />
{<br />
}<br />
}<br />
<br />
MyClass myObj = new MyClass<br />
myObj.A = 90;<br />
Thread t = new Thread(new ThreadStart(myObj.show));<br />
t.Start();<br />
In .NET 2.0, we have a ParameterizedThreadStart delegate which will allow you to pass parameters to the methods while creating threads.
My small attempt...
|
|
|
|
|
Question - How can the profile provider be specified at runtime?
Explanation:
I have two systems, one for 'Test' and one for 'Live' and each has a Sql Server.
When 'Test' code is published to 'Live' I currently have to edit connection strings in web.config to ensure that the live system does not access the test database and vice versa.
This method is prone to error so for Membership and Roles, I have created providers for Test and Live and select the correct provider at runtime. (This is achieved by recognising the machine name of the Test server).
eg
MembershipProvider myMembershipProvider =
Membership.Providers["CustomAspNetSqlMembershipProvider"];
MembershipUser myMember = myMembershipProvider.GetUser(strUsername, true);
However, the same syntax does not seem to be available for Profile.
I need to select the profile provider at runtime, but the defaultProvider is always used.
Extract from Web.config
<profile enabled="true" defaultprovider="CustomAspNetSqlProfileProvider" automaticsaveenabled="true">
<providers>
<clear>
<add name="CustomAspNetSqlProfileProvider" connectionstringname="LiveSqlServer" applicationname="myApp"
="" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<add name="LocalAspNetSqlProfileProvider" connectionstringname="LocalSqlServer" applicationname="myApp"
="" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<properties>
<add name="Firstname">
<add name="Lastname">
<add name="Comments">
The following code creates a ProfileCommon using the default provider
ProfileCommon mProfile = new ProfileCommon();
mProfile.Initialize("myUsername", true);
I would like to use the LocalAspNetSqlProfileProvider on the 'Test' system, and use the CustomAspNetSqlProfileProvider on the 'Live' system.
The following line fails because the 'Live' SQLServer is unavailable from 'Test'
TextBox1.Text = mProfile.Firstname;
How can the profile provider be specified at runtime?
|
|
|
|
|
Oops - I didn't realise that xml tags would be stripped. Here's the web config again.
Extract from Web.config
<profile enabled="true" defaultProvider="CustomAspNetSqlProfileProvider" automaticSaveEnabled="true">
<providers>
<clear />
<add name="CustomAspNetSqlProfileProvider" connectionStringName="LiveSqlServer" applicationName="myApp"
type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add name="LocalAspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="myApp"
type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
<properties>
<add name="Firstname"/>
<add name="Lastname"/>
<add name="Comments"/>
</properties>
</profile>
|
|
|
|
|
Hi
Can we use a dll file of .net in vb project or can we use a vb file in .net project. if yes how can we do that.
Thanks & Regards
Mishra
|
|
|
|
|
Only if built as COM objects.
|
|
|
|
|
|
thread s;
public Form1()
{
s= new Thread (new ThreadStart (ms));
InitializeComponent();
}
form _load
{
s.start();
}
void ms()
{
messagebox ("startes");
}
but the problem is thread messagebox is hosed only once , but i want to keep
it showing again and again untill the thread is started
can u tell me where i am wrong
hello
|
|
|
|
|
ReaderWriterLock readerWriter = new ReaderWriterLock( );
bool threadStarted=false;
public Form1()
{
s= new Thread (new ThreadStart (ms));
InitializeComponent();
}
form _load
{
s.start();
while(!threadStarted)
{
messagebox ("startes");
}
}
void ms()
{
readerWriter.AcquireWriterLock(1000);
try
{
threadStarted=true;
/// Thread code
}
finally
{
readerWriter.ReleaseWriterLock( );
}
}
|
|
|
|
|
hi
i have a comm device which reads data via a card reader ,,
it has an interface created in vb6 with a dll named "comm.dll"
there is a method named opencomm in this dll
when i call this method from vb code the comm opens and device works fine means it showd that it is not connected with computer comm port,,
but when i do the same thing in the c#.net , and open the comm using serial port object ,, it does not connect with the device altough comm open successfully ...
please help me out
thanks in advance
hello
|
|
|
|
|
"A call to PInvoke function 'CSharpDoorMagic!CSharpDoorMagic.Form1::OpenCommPort' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature. "
whats this error about and why it is showed?
thanks in advance
hello
|
|
|
|
|
IT means you're using p/invoke, and signature is wrong, I would have said...
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Most likely the unmanaged code is __cdecl but the P/Invoke declaration had CallingConvention=CallingConvention.Winapi (which is the default), which maps to CallingConvention.Stdcall on x86.
Windows on x86 has a number of calling conventions which define how parameters are passed to a called function, and whose responsibility it is to clean up. The __cdecl calling convention is the default for C and C++, where the calling function pushes the parameters onto the stack from right to left (last parameter first, so the first parameter is on top of the stack), and the calling function is also responsible for removing them again. This aids in implementation of functions with variable argument lists (similar to params in C#) since the first argument is always in the same place, and the called function doesn't need to know how many arguments were pushed.
The OS uses the __stdcall calling convention on x86, originally to save a little code space. This convention pushes the arguments in the same way as __cdecl , but now the called function is responsible for removing the arguments from the stack.
Because this is such a common mistake, the CLR contains code to detect, after making a P/Invoke call and doing any required adjustments, that the stack pointer is what it was before the function was called. It doesn't correct the problem because there could be other reasons for an unbalanced stack.
The problem goes away on mobile devices and 64-bit operating systems, where there is only one calling convention.
To correct it, you probably need to set CallingConvention=CallingConvention.Cdecl on your [DllImport] attribute. If in VB and using a Declare statement, you'll have to convert to using the DllImport attribute.
|
|
|
|
|
Thanks i have got that and now i can access the function from this dll, and can open, close and get values from the comm but only using the functions in this dll..
but now the problem is i cannot fire datareceived event on the com port which i assign
to open method of this dll,,
int hc = OpenCommPort("COM1", 9600);///method from dll which open the com1
int rtt = ReadValue(hc);///mehtod from dll
now i do the following
sp = new SerialPort("COM1",9600);
sp.DataReceived += new SerialDataReceivedEventHandler(method);
if (sp.isopen);
{
show ("Open");//but here it shows that com port is closed ,, so i cannot manage
data received event handler for this com port ,,
}
please tell me in the scenario what shud i do ?
void method()
{
// this method shud be called when the ( int rtt = ReadValue(hc)
is called...but it does not , even i get an error when i try to open
sp using sp.open();
aftehr when i have called the dll function
int hc = OpenCommPort("COM1", 9600)
so please tell me how to create a handler for the situation ,, means the port which
i assign to the dll method opencommport there shud be a handler for that
thakns in advance
hello
|
|
|
|
|
CType(applicationObject, Word.Application).CustomizationContext = CType(applicationObject, Word.Application).ActiveDocument
CType(applicationObject, Word.Application).ActiveDocument.Saved = True
"You can do any thing you set to your mind" - theGhost_k8
|
|
|
|
|
|
oh !! i missed out the important part..
well this works fine when i go:- start-> run-> winword
it works fine when i go with debuging..
but if i run existing document by double clicking... it gives error .. specifying activeDocument not exist..
"You can do any thing you set to your mind" - theGhost_k8
|
|
|
|
|
Hi,
I've got an object that is serializable. It implements the IDeserializationCallback interface, to perform some additional work after it's been deserialized.
It works fine if I use a SoapFormatter to serialize/deserialize the object, but if I pass the object to a WebMethod, the OnDeserialization method never gets called. I'm obviously incorrect in assuming that WebMethods use SoapSerialization to pass objects.
Is there any way I can get a post deserialization method of some kind to be called after the WebMethod has finished deserializing the object?
Can anyone help?
Thanks
|
|
|
|
|
Hello. Is it possible to use SQL Server 2000 Notification Services together with .NET 2.0 client. Thanks in advance.
|
|
|
|
|
Yes it is.
.Net 2.0 connects to sql 2000 or sql 2005 without even changing a line of code. As SQL Server 2000 Notification Services is part of Sql 2000 and primarily watches for table updates you can use it without problems. I have been working on a big project that migrated from .Net 1.1 to .Net 2.0 a year ago, but we only moved up to SQL 2005 six months ago, primarily because nofification services is much better integrated with SQL in 2005.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
|
|
|
|
|
Thank's a lot for your answer. There's too little information on this topic in internet and I'm just a beginner in notification services.
|
|
|
|
|
Hi all,
Actually i was looking for automatic background process to deliver mails if certain condition met in database so i posted a question last week and i received suggestion to create Windows services to do it.
Unfortunatly I never worked with windows services so i created a small service and installed it without any trouble. But i am not able to start it. When am trying to start its giving be alert box saying "This service has been started and stopped. Some service stop automatically if they have no work to do."
But i have created the service with timer to trigger every 30 sec to write an entry to a database table.
Looks like i cannot start the service at all. Also i tried to debug it but i could not find my service.exe in the list to attach since it is not running. {instead i found explorer.exe which is new and from the same path my service.exe exists. But physically explorer.exe is not existing in that folder)
please some one help me in fixing this. Am i missing something?
Thanks in advance
Renu
|
|
|
|
|
There is a few registry flags that controls how services are run. One of these options, I think, is to have the service run in its own process or as part of a system process (cant remember which one). If the service is set to run as part of this system process it will be loaded with LoadLibrary() and executed on a thread of this system service. I think thats why you cant see it. Search around for details of the registry entries assosiated with a service.
For debugging I always used __asm{int 3} in c++ to break into the debugger but you probably cant do that in .Net
Why dont you put something in your init routine that will cause an exception. Then windows will show you the unhandled exception dialog and give you the option to debug the process
Generally I think it is easier to develop your app as an exe and then convert it into a service once its all debuged and running.
|
|
|
|
|
It sounds like your Main routine is simply returning without registering with the service control manager (not calling System.ServiceProcess.ServiceBase.Run ) or that the service's OnStart method is simply quitting. I can see that a working service we have here is creating a new thread in OnStart to do its work. This is virtually required because the OnStart method is expected to return back to the SCM fairly quickly - otherwise the control application will report that the service failed to start.
To debug service startup, we add the following to the top of Main :
#if DEBUG
System.Diagnostics.Debugger.Launch();
#endif This causes the Just-in-Time debugging window to appear, asking you which instance/version of VS you want to debug with.
|
|
|
|
|
Hi,
You are 100% correct. The problem was service's OnStart was simply quiting without doing anything. So i created a new thread in Onstart and it does solved the problem. The service is running without any trouble. Also since it is running i can locate it in running process list to attach to debug.
Your suggestion solved both of my problems. Thank you so much for you both Mike and Josh. Thanks a lot for your timely help.
Renu
|
|
|
|
|
Does .NET support DDE? Can we build DDE Clients and Servers in .NET? If yes, can an unmanaged application written in VC++6 or VB 6 communicate with a managed application using DDE?
---
Hakuna-Matada
It means no worries for the rest of your days...
It's our problem free, Philosophy
|
|
|
|