|
What do "client number"s and ServiceThrottling settings have to do with each other?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Isn't the servicethrottling onyl way of limiting numbers of clients that can connect to server by controlling service instances and concurrency? So I want to limit max connections to a specific number of clients
|
|
|
|
|
Have you tried using sessions and limiting the number of sessions?
Besides the configuration you've shown, make sure sessions are required and concurrency/instance context modes are set on the service contract:
[ServiceContract(SessionMode = SessionMode.Required)]
public interface IService1
{
}
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerSession)]
public class Service1 : IService1
{
}
Sessions, Instancing, and Concurrency[^]
Discover Mighty Instance Management Techniques For Developing WCF Apps[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello,
I want to do the integrity check zip files, I would use 7zip library with the command 't' using this code:
try
{
Process rr = Process.Start(@"..\Release\7Z\7z.exe ", @" t ..\Release\.zip > .\1.test");
rr.WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Order fontionne well on the lin command (CMD), except with the code below, it doesn't generate the file 1.test.
Thank you verry mutch.
|
|
|
|
|
abbd wrote: it doesn't generate the file 1.test.
If 7z had encountered an error, it would have written that to the file ".\1.test". There's also a space at the end of your path to the 7z-executable, that shouldn't be there. Does it print anything on the console if you run it?
Bastard Programmer from Hell
|
|
|
|
|
Hi,
I need to enumerate directories/shares (and their permissions), so far, I found two appraches:
OPTION 1: WMI[^]
- advantage: You can query remote computers if you have the permission to...[^]
- limitation is that: (a) Don't give local path, (b) I need "Permission", noth NTFS+Share, which WMI object don't provide.
This said, I did came across Win32_SecuritySettingOfObject[^], but don't know how to use it. And still trying Win32_SecuritySetting (But samples are so hard to decipher, for example, ControlFlags = 32772. This means absolutely nothing to me) [^] - how to get list of users/groups assigned to access to share folder?[^]
After more digging around, seems like answer (last challenge) is to call Win32_Share.GetAccessMask from C#[^] --- HELP! Sample from here don't work...[^]
OPTION 2: DllImport win32 API - WNetGetUniversalName and NetShareEnum [^]
- advantage: gives local path of identified shares and also able to scan both local/remote shares
- limitation: Option 2 actually gives local path, but nothing on directory/share "Permission".
note SHARE_INFO_2 has an "Permission (int)" field, but after examining further doesn't appear this is what I'm looking for. Also examined new System.IO.DirectoryInfo(share.Path) --- nothing useful from there.
Any suggestion guys? I need permissions - both NTFS+Share access permissions[^]... (Basically same as right click folder, select "Properties", look under "Security" tab and also "Sharing\Permissions")
Thanks!
OPTION 1 - sample code:
<br />
<br />
public static IList<string> EnumerateLocalShares(ShareCheckingMode Mode)<br />
{<br />
IList<string> Shares = new List<string>();<br />
SelectQuery query = null;<br />
ManagementObjectSearcher searcher = null;<br />
<br />
switch (Mode)<br />
{<br />
case ShareCheckingMode.Win32_LogicalShareAccess:<br />
query = new SelectQuery("SELECT * FROM Win32_LogicalShareAccess");<br />
break;<br />
case ShareCheckingMode.Win32_LogicalShareAuditing:<br />
query = new SelectQuery("SELECT * FROM Win32_LogicalShareAuditing");<br />
break;<br />
case ShareCheckingMode.Win32_LogicalShareSecuritySetting:<br />
query = new SelectQuery("SELECT * FROM Win32_LogicalShareSecuritySetting");<br />
break;<br />
}<br />
<br />
searcher = new ManagementObjectSearcher(query);<br />
foreach (ManagementBaseObject share in searcher.Get())<br />
{<br />
Console.WriteLine("Share: " + share.ToString());<br />
foreach (PropertyData prop in share.Properties)<br />
{<br />
Console.WriteLine("Property - " + prop.Name + ": " + prop.Value);<br />
}<br />
foreach (PropertyData prop in share.SystemProperties)<br />
{<br />
Console.WriteLine("SystemProperty - " + prop.Name + ": " + prop.Value);<br />
}<br />
foreach (QualifierData Qualifier in share.Qualifiers)<br />
{<br />
Console.WriteLine("Qualifier - " + Qualifier.Name + ": " + Qualifier.Value);<br />
}<br />
Console.WriteLine();<br />
Console.WriteLine();<br />
}<br />
<br />
return Shares;<br />
}<br />
For NTFS folder permission (Not "Share" permission) [^]
<br />
public static FileSystemAccessRule GetDirectoryPermissions(string user, string domainName, string folderPath)<br />
{<br />
if (!Directory.Exists(folderPath))<br />
{<br />
return (null);<br />
}<br />
<br />
string identityReference = ((domainName + @"\" + user) as string).ToLower();<br />
DirectorySecurity dirSecurity = Directory.GetAccessControl(folderPath, AccessControlSections.All);<br />
foreach (FileSystemAccessRule fsRule in dirSecurity.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))<br />
{<br />
if (fsRule.IdentityReference.Value.ToLower() == identityReference)<br />
{<br />
return (fsRule);<br />
}<br />
}<br />
return (null);<br />
}<br />
dev
modified on Wednesday, May 18, 2011 6:36 AM
|
|
|
|
|
I think I found how to enumerate share permissions. However, I can't interpret AccessMask = 1179817, MSDN didn't help (none of listed constants matches 1179817)[^]
I stumbled across this[^]
<br />
# Constants<br />
$SHARE_READ = 1179817<br />
$SHARE_CHANGE = 1245462<br />
$SHARE_FULL = 2032127<br />
$SHARE_NONE = 1<br />
Compared against actually setting, "1179817" is indeed READ.
<br />
ManagementObject sharedFolder = WMIUtil.GetSharedFolderObject("TestShare$");<br />
ManagementBaseObject securityDescriptorObject = sharedFolder.InvokeMethod("GetSecurityDescriptor", null, null);<br />
ManagementBaseObject securityDescriptor = securityDescriptorObject.Properties["Descriptor"].Value as ManagementBaseObject;<br />
int existingAcessControlEntriesCount = 0;<br />
ManagementBaseObject[] accessControlList = securityDescriptor.Properties["DACL"].Value as ManagementBaseObject[];<br />
existingAcessControlEntriesCount = accessControlList.Length;<br />
Array.Resize(ref accessControlList, accessControlList.Length + 1);<br />
foreach (ManagementBaseObject o in accessControlList)<br />
{<br />
WMIUtil.DisplayProperties(o);<br />
}<br />
<br />
Now ...
<br />
public static void DisplayProperties(ManagementBaseObject o)<br />
{<br />
if (o == null)<br />
{<br />
return;<br />
}<br />
<br />
Console.WriteLine();<br />
Console.WriteLine("Object: " + o);<br />
<br />
foreach (PropertyData prop in o.Properties)<br />
{<br />
if (prop.Value is ManagementBaseObject)<br />
{<br />
ManagementBaseObject childObj = (ManagementBaseObject)prop.Value;<br />
DisplayProperties(childObj);<br />
}<br />
else<br />
{<br />
Console.WriteLine("Property - " + prop.Name + ": " + prop.Value);<br />
}<br />
}<br />
<br />
foreach (PropertyData prop in o.SystemProperties)<br />
{<br />
Console.WriteLine("SystemProperty - " + prop.Name + ": " + prop.Value);<br />
}<br />
<br />
foreach (QualifierData Qualifier in o.Qualifiers)<br />
{<br />
Console.WriteLine("Qualifier - " + Qualifier.Name + ": " + Qualifier.Value);<br />
}<br />
<br />
return;<br />
}<br />
dev
modified on Thursday, May 19, 2011 3:30 AM
|
|
|
|
|
Is there a chance for a Dispose() method to be called by GC if class is not inhereted from IDisposable?
class My
{
public void Dispose()
{
}
}
I provided that method to immediatly release some memory resources for the class.
I wonder if it is prohibited to name some functions after well known methods as Dispose?
I experience the following problem Windows service stable APPCRASH in clr.dll after 3.5 to 4.0 .NET platform change[^] which occur in windows service application only.
Чесноков
|
|
|
|
|
The runtime won't call it, but will it be confusing to future people looking at the code?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The GC calls Dispose methods only on IDisposable objects. So, in your case GC will not call the Dispose method. Although it is not illegal to use the name 'Dispose' for your cleanup methods, other developers who work with your code may get confused.
EDIT:
I meant to say the that the GC calls the finalizer which in turn is supposed to call Dispose method. The GC does NOT call Dispose method directly even if the class implements IDisposable interface.
However, in a using code block, the C# compiler checks if the class implements IDisposable interface when compiling the code into a try...finally... block and calls its Dispose method in the finally block.
modified on Wednesday, May 18, 2011 9:44 AM
|
|
|
|
|
As it stands, Dispose is just a method name. The trick with IDisposable objects is that the interface is well known, so it can be accessed using (effectively):
IDisposable = thisClass as IDisposable;
if (thisClass != null)
thisClass.Dispose();
|
|
|
|
|
Shouldn't the code be something like this?
IDisposable i = thisClass as IDisposable;
if (i != null) {
i.Dispose();
}
|
|
|
|
|
It should. That's what I get for typing replies on a phone.
|
|
|
|
|
Never mind, as long as it conveys the idea. But beginners might have a problem though.
|
|
|
|
|
Maybe, if it's called from the finalizer.
But I would implement the IDisposable interface, it's free.
|
|
|
|
|
Hello Experts,
I want to open autocad file in my application so please suggest me what component or library is the best for this usage.
Thanks
If you can think then I Can.
|
|
|
|
|
Google[^]!
The best things in life are not things.
|
|
|
|
|
This may help[^]
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
I'm looking to add threading support to an application I'm working on, and am looking for advice on how to accomplish this.
I have a collection of objects which are updated through a foreach loop. Instead, I'd like to dedicate this to a series of threads, where each object is moved in for processing as the thread becomes available.
I've come up with 2 approached on how to do this.
Method 1: Using a WaitHandle
Give each thread an AutoResetEvent and rely on the WaitHandle.WaitAny() method to identify when a thread is finished so a new one can be created.
Link: MSDN[^]
Pseudocode:
void QueueThreads(IEnumerable myCollection, uint maxThreads)
{
uint usedThreads = 0;
AutoResetEvent[] autoEvents = new AutoResetEvent[Math.Min(maxThreads, myCollection.Count)];
foreach (T myObject in myCollection)
{
if (usedThreads < maxThreads)
{
autoEvents[usedThreads] = new AutoResetEvent(false);
usedThreads++;
}
else
{
uint freeThreadID = WaitHandle.WaitAny(autoEvents);
usedThreads--;
usedThreads++;
}
}
WaitHandle.WaitAll(autoEvents);
}
void DoWork(myObject, AutoResetEvent are)
{
are.Set()
}
Method 2: Sharing the enumerator across threads
Give each thread access to the enumerator used to iterate over the collection. Each thread stays alive until all items in the collection have been exhausted.
Pseudocode:
void QueueThreads(IEnumerable myCollection, uint maxThreads)
{
uint usedThreads = 0;
IEnumerator myCollectionEnum = myCollection.GetEnumerator();
for (uint i = 0; i <= Min(myCollection.Count,maxThreads); i++)
{
}
myCollectionEnum.Reset();
}
void DoWork(IEnumerator myColEn)
{
do
{
T myObject;
lock (myColEn)
{
if (myColEn.MoveNext())
{
myObject = myColEn.Current
}
else
{
break;
}
}
}
}
My experience with threading has been only experimental, so I'm hoping the CP threading vets can provide input on which approach is best, or if there's a third option worth considering.
As for starting a thread, I’ve seen a few different methods for doing this (ThreadPool.QueueUserWorkItem() , new Thread(new ThreadStart()) , BackgroundWorker ) , but don’t really know when to use which one.
Note that file/database IO would need to be synchronized between the threads, but aside from that, there shouldn't be any issued with shared resources as each object maintains its own state.
Also, I am restricted to using .Net 2.0.
modified on Thursday, September 15, 2011 2:37 PM
|
|
|
|
|
The question to ask would be why you are trying to use multiple threads, what are you expecting to gain from it? If it is increased performance you may not get what you are looking for since the bottle neck would most likely be at the file IO or database level.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Essentially, this process would be to collect data from a list of networked machines. Most of the latency comes from locating the machine and then establishing a connection. The threading is so I could continue to process other machined while one is waiting to connect.
|
|
|
|
|
IIRC the number of concurrent TCP/IP connections you can establish is limited to a few tens, which wouldn't be a problem, unless you try and connect to a lot of machines that are absent or off, as those connection attempts would hit a time-out (possibly 1 minute).
BTW: using lots of threads for actions that are mostly blocking (waiting on something) rather than computing, is quite wasteful. A better approach could well be to apply asynchronous operations (similar to serving all WinForms Controls from a single thread).
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Yes, I do expect that I will get a timeout for many of the connections. I'm starting with 10 threads, but will probably adjust that number once I get a better idea how the threads perform.
Luc Pattyn wrote: BTW: using lots of threads for actions that are mostly blocking (waiting on
something) rather than computing, is quite wasteful. A better approach could
well be to apply asynchronous operations (similar to serving all WinForms
Controls from a single thread).
There's a difference? I've always understood "asynchronous programming" to be just a different term for threading.
|
|
|
|
|
Of course there is a difference, a rather big one.
In multi-threading you write code in sequential mode: lets do A, then wait for B, then do C, then wait for D, etc. That is easy to write as the program counter is your main state variable; now each thread needs a stack (so it can remember where it is when nesting functions/methods), and the operating system has to switch threads all the time.
In asynchronous operation, you could have just one thread; the workload is split in small jobs, and the thread executes these jobs one at the time, to completion. That is how Windows does a WinForms GUI: you have a button handler, a paint handler, etc. Now if you need to split a long-winding operation over multiple handlers, you need some state variables, you basically build a state machine, which is event-driven, not progressing based on the program counter.
Consider a serial port receiver: with its own thread, you can write like: now I expect this, then I wait, then I should get some acknowledge, then wait, then get a length, then some amount of data, etc. With a DataReceived handler, your handler has to reflect on "what am I getting know" and "where was I in the protocol", and make those match up.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Yes. it seems that the asynchronous network access in the framework (Socket.BeginReceive etc) is the way forward here.
|
|
|
|
|