|
Hi
I was wondering if anyone familiar with the workings of the .NET TcpClient and TcpListener classes could help.
The problem is that closing TcpClient connections doesn't actully seem to close them, according to the performance counter "NET CLR Networking -- Connections Established": the count just gets higher and higer - it doesn't even come down when I restart the applications
Now, for a simple test case, I have a server component with TcpListener:
TcpListener listener = new TcpListener(PORT);
TcpClient client;
for (;;)
{
if (listener.Pending)
{
client = listener.AcceptTcpClient();
Console.WriteLine("Connection established");
client.Close();
}
}
A client opens up a connection, sleeps for one second and then closes it.
On a live system, as the connection count gets higher, the data transfer rate gets lower and lower until it eventually stops and the W2K workstation has to be restarted.
Any ideas on how I can fix this and force these connections to close?
thanks
ehuysamer
|
|
|
|
|
If you call TcpClient.GetStream(), you also need to close the Stream in addition to the TcpClient.
|
|
|
|
|
I'm having some inconsistency problems with my deployment project ("Setup") and its custom actions ("Installer"). I'm using Visual Studio .NET 2003 (.NET 1.1, no service pack) on Windows XPSP1.
My main project is a band object (Explorer Bar) in an assembly (.DLL) that needs to be registered on installation and unregisted on uninstallation. In addition, during installation, Setup creates registry subkeys, sets registry values, installs some application files, and adds a new file-type. On uninstallation, Setup is supposed to undo all of that. More specifically, I have custom actions for Setup that are run within the Installer class. The Installer class is within the main assembly, and perhaps surprisingly, that seems to work, some of the time. I have also tried putting the Installer class in its own assembly, both as a class library and as a console application, and that doesn't seem to work any better than having the Installer class in the main assembly. Sometimes the registration or unregistration of the main assembly fails. The workaround we tell our users (a small userbase so far, fortunately) is to "repair" after installation, or to uninstall completely before installing a new version. Neither are as ideal as being able to simply install over the previous version. I think there are two subproblems.
1) The Uninstall custom action in the Installer class isn't always called. This is especially inconsistent. My Installer class overrides OnBeforeUninstall() [so that the main assembly is unregistered before the files are removed] and Uninstall() [so that savedState is empty, in order for the installState to be removed]. Lacking better debugging tools for MSIs, I added code in these methods to set registry entries containing the timestamp at the beginning and end of each of these methods. I verified that usually the Uninstall custom action is (but not always) called when the user explicitly asks to remove the package (via "Add/Remove Programs"), but when the user is installing over a previous version, sometimes (but not always) the Uninstall custom action is called. As a side note, I change the installer version, PackageCode, and ProductCode whenever I build a new installer. I don't understand why these inconsistencies occur. For a while I thought VS.NET might randomly corrupt the Setup.vdproj file and that I'd have to remove and add the custom actions again, in order to be sure that the Uninstall custom action was registered, and once or twice I built the Setup.vdproj file from scratch, fearing general corruption in the file. This seemed to help (especially the latter), but not for too long, and it's not a sustainable solution, even if it's not a placebo. In addition, which may or may not be related, the Setup.MSI doesn't seem to always uninstall all registry entries, and because of that, I've had to add a few lines to my Uninstall custom action. It doesn't seem right to me that the MSI would sometimes not uninstall registry entries that it added in the first place.
2) The second subproblem is more specific to my project, and this occurs sometimes when I'm registering the main assembly. The main assembly is registered in the overridden OnCommitted() method of the Installer class, presumably after the previous version's main assembly was unregistered in the OnBeforeUninstall() method. In the case where the previous version and the new version were installed in the same "Program Files" folder, the assembly containing the Installer class will have the same exact CodeBase, but they'll of course have a different FullName because the assembly version has been automatically incremented. It seems that sometimes the Commit custom action will re-register the old assembly instead of registering the new assembly. My registration code looks like this:
RegistrationServices rs = new RegistrationServices();
rs.RegisterAssembly(MyAssembly, AssemblyRegistrationFlags.SetCodeBase); and my unregistration code looks like this:
RegistrationServices rs = new RegistrationServices();
rs.UnregisterAssembly(MyAssembly); MyAssembly is defined as a property:
Assembly MyAssembly
{
get
{
return Assembly.LoadFile(InstallDirectory + "assembly.dll");
}
} I used to use Assembly.Load(path) instead, but it seemed that Assembly.LoadFile(path) worked better. My concern is that either the Uninstall and Commit custom actions share an AppDomain, so sometimes MyAssembly might return the previous assembly during the Commit phase if the previous assembly wasn't somehow still in Commit's AppDomain after Uninstall finished. I tried creating a temporary AppDomain and then loading the assemblies within that, but it threw a deserialization exception. I suppose the overall issue of this subproblem is that I'm trying to register and unregister assemblies without knowing the FullName of either assembly, as I'm trying to semi-automate the build process and stay within VS.NET as much as possible (for now).
I know these are complex and possibly peculiar problems! While I'd love for someone to post a solution for either (or both!) subproblems, at the very least, I'd appreciate hearing tips regarding debugging deployment projects and custom installation classes, similar stories of installer woes and solutions, and recommendations for possibly better installation/deployment tools than VS.NET's deployment projects. Something like InstallShield seems like overkill, but maybe it's what I need to have dependable installations.
Thanks for reading this far!
Arun
|
|
|
|
|
sorry my English is bad
DataSet ds=new DataSet();
IDbDataAdapter ida=helper.GetDataAdapter();
ida.MissingSchemaAction=MissingSchemaAction.AddWithKey;
ida.SelectCommand=helper.CreateCommand(conn,"select * from A;select * from B",CommandType.Text,null);/////////this row code CommandString error,what?
ida.Fill(ds);
i use access database
i think create many table of dataset
|
|
|
|
|
xiaoyuan wrote:
helper.CreateCommand(conn,"select * from A;select * from B",CommandType
IIRC, Access/Jet SQL doesn't support compound statements. Try breaking them up into two different calls:
ida.SelectCommand=helper.CreateCommand(conn,"select * from A",CommandType.Text,null);
.
. Execute the command
.
ida.SelectCommand=helper.CreateCommand(conn,"select * from B",CommandType.Text,null);
.
. Execute the new command
.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hai guys,
is it possible to serialize a hashtable that contains objects of a class and that particular class contains a hashtable? If it is possible, Please give me your valueble advice
Regards,
Rathish P S
|
|
|
|
|
The HashTable class is itsself serializable. If it only contains object which are either implementing ISerializable or having the Serializable attribute there no reason why you should not be able to serialize it.
Just try marking all classes within the HashTable (and also references other classes) with the Serializable attribute and then serialize it:
<br />
System.Runtime.Serialization.Formatter f = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();<br />
f.Serialize(myStream, myHashTable);<br />
Thats basically all you HAVE to do. There are many problems which can arise, especially when it comes to efficiency. You are free to ask again if you reach such a point
|
|
|
|
|
Ok im so confussed why this happens, but it does...everytime.
In my custom list control, when i add items to the control, the scrollbars adjust.
Now all this works like clockwork until i start adding items to the control from a thread...at which time the items get added just fine to the collection, but after a few milliseconds of adding i see the scrollbar thumb shrink and shrink and then the whole scrollbar literally DIAPPEARS!
I accessed that controls properties with propertygrid when the problem happens and it reports that the control is visible and right where it should be with a viewable size. I really don't know what to do...i think trying to update a scrollbars largechange and maximum from asynch requests to add causes it to bug out...
If theirs no fix for this im gonna have to make my own scrollbar...something that can stand up to the stress.
|
|
|
|
|
Accessing windows controls from threads other than the one which instanciated them has often weird results.
Therefor try to invoke the adding of items, so it gets executed on the thread that instantiated the control. See the docs for the Control.Invoke[^] method for some more infos.
www.troschuetz.de
|
|
|
|
|
Can you show me some example of what the function i pass to my scrollbar's.Invoke looks like. Like parameters and return type... Just never used invoke before and ironically i saw an article on threading on msdn the other day that was just what i needed, but it's not in my browsers history!
|
|
|
|
|
wait nvm, i found what i needed in someone's blog.
Link provided if anyone else needs to know this stuff http://blogs.bartdesmet.net/bart/archive/2004/11/07/462.aspx
|
|
|
|
|
can anyone teach me how to connect to a email server to send emails through my email name??
|
|
|
|
|
|
I perhaps can sympathise that this wasn't as simple to find.
When I first tried to use it I found it hard to know what I was looking for, so here's a sort of sample class that might help you out.
public class EmailSender
{
MailMessage mailMsg;
public EmailSender(string to)
{
mailMsg = new MailMessage();
mailMsg.From = "Me@frommySMTP.com";
mailMsg.To = to;
SmtpMail.SmtpServer = "10.10.10.XXX";
}
public void sendMessage(string subject, string body)
{
mailMsg.Subject = subject;
mailMsg.Body = body;
SmtpMail.Send(mailMsg );
}
}
Even if the class doesn't serve your purpose the code should give you an idea.
I think the include is like:
using System.Web.Mail;
You will have to reference that yourself.
Hope this helps,
Jim
P.S. For exchange servers your going to need to look up MAPI.
|
|
|
|
|
|
hey.... i have something very weird...
using System.Web.Mail; is the correct way of doin this....but when i put it into my references, it does not work and i get a build error.... what does that mean??
|
|
|
|
|
Hi,
How to create a ColumnHeader with 2 header lines for a listView?
eg: | country1 | country2 |............|
|------------|-----------------|------------|
|city1|city2 |city3|city4|city5|............|
Thanks
chesslin
|
|
|
|
|
Does anybody know if you can create an C# class object from vba pasing parameters through the constructor. if not, then the constructor can only be one for each class and no parameters? I did overload a function in c # and vba did not recognise this. Anybody with knowledge here would be greatly appreciated,
Regards
Mit
notsnoj
|
|
|
|
|
VBA is not aware of constructors. In fact, COM itself - VBA being an OLE automation client which is built on COM - is not aware of constructors.
COM describes calling methods on objects, not how the objects are obtained. A common workaround for a complete lack of constructs is an initialization method of sorts, in which you'd pass parameters that you'd normally pass to a constructor.
To expose a "C# class" (BTW, all C# codes - like other managed languages - compiles to IL so it's all basically the same, sans compiler optimizations and language features) to COM you must actually have a public constructor (either inheritted or defined). If not, you can expect a COM error to be raised (or a managed exception to be thrown, depending on the circumstances).
You should also follow COM guidelines, like attributing all classes and interfaces with a unique GuidAttribute value and not using auto-generated class interfaces, but explicitly defining your own. Never change a published interface, either, but derive from it and implement that as the first interface for your class (which the CLR treats as the class interface).
Read Exposing .NET Framework Components to COM[^] and Design Considerations for Interopation[^] in the .NET Framework SDK for more information.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thankyou very much for this information.
Regards
Mit
notsnoj
|
|
|
|
|
I need to get icons for special folders, such as Desktop, My Computer, My Documents, etc.
I've been able to use the SHFILEINFO API to get icons for drives, regular folders and, of course, files... however, I can't seem to figure out how to get the icons for the 'special folders'
I've been told to use the Environment namespace, but I don't see how that will help me. Apparantly I need to get and pass a pidl for the special folder to SHFILEINFO, but... again, I'm not sure how to do either.
I'm relatively new to C#, so I could be entirely mistaken about how I'm supposed to get these icons. If there are any other ways I can do this, do let me know.
Any help would be greatly appreciated!
|
|
|
|
|
If you read the linked documentation in the Platform SDK PIDLs are discussed in great detail. The easiest way to get these is to navigate from the desktop to the shell namespace and/or folder to get the PIDL. You can do this easily by creating an RCW (runtime-callable wrapper) using either tlbimp.exe or adding a reference to your project using the COM tab for the "Microsoft Shell Controls and Automation" typelib.
See the Shell Objects for Scripting[^] for documentation. How you use the classes is essentially the same (though not 100%) because the automation objects provide functionality to automation clients like Windows Script, VB6, and RCWs.
It would be easier and require less dependency to P/Invoke SHParseDisplayName , but you really must read the documentation to understand what you're passing, since it requires that you also pass an IBindCtx (the interface is declared as System.Runtime.InteropServices.UCOMIBindCtx , but you must still get an instances by P/Invoking CreateBindCtx ).
Experience with shell programming and COM is extremely helpful, and there's a lot of information in the Platform SDK to give you hints on how to do this. Understanding COM interop is also important.
If you have specific questions, please ask. Do first read the documentation, however, since you need to understand the native code in order to know what and how to P/Invoke it correctly, like redefining your SHGetFileInfo signature to access either a string marshaled correct (see the Marshal class for help) or a PIDL, which is an ITEMIDLIST structure which you may or may not have to define depending on how you use it (you could just declare it as an IntPtr if you don't need to parse it yourself).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
If thread A raises an event E and thread B has the handler, is there any different to use E(...) and E.BeginInvoke(...)? They are both asynchronous anyway, right?
|
|
|
|
|
No, they are not both asynchronous. If you simply invoke an event (a MulticastDelegate ) it is fired in the context of the calling (invoking) thread. If you use BeginInvoke a new thread from the thread pool is grabbed and used to execute the handler. If you want to execute the handler on the thread that instantiated the class (very important for Control classes in Windows Forms), then the object implementing the handler must implement ISynchronizeInvoke (or similar functionality - that that would be up to you) and you call its ISynchronizeInvoke.Invoke implementation.
Read Handling and Raising Events[^] and Threading[^] in the .NET Framework SDK for more information. You should also read the documentation[^] for the Control.Invoke method if you're dealing with threading in a Windows Forms application.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I debugged the code step by step. What confused me is why when I invoked an event from a thread (NOT using begininvoke), the code immediately returned and continued to execute rest of code in the calling thread? Isn't it supposed to run the delegate func first and then return?
|
|
|
|
|