|
Maybe the problem is with how I create the backgroundWorker. From my form class, I am doing the following (I create two of these..one for each form tab):
if (!backgroundWorker1.IsBusy)
{
try
{
backgroundWorker1.RunWorkerAsync();
}
}
Is there a way I can still have the user able to hit a button on the form, yet have the backgroundWorkers hog more of the processor so they can have priority over the form and other things on the computer?
|
|
|
|
|
I just use Threads, not BackgroundWorkers, and I always set them for lower Priority.
|
|
|
|
|
I am testing code that uses backgroundWorker. A similar application run on a different computer runs code that is practically the same, and is faster, but doesn't use backgroundWorker. Could the backgroundWorker be taking longer than code that doesn't use the backgroundWorker? Other differences are 32 bit vs 64 bit(mine)computer. My code also uses more dll's, but using a profiler with my code, the part that was taking long was a repeated call to an external dll, which the other code also does.
|
|
|
|
|
The answer is that you aren't comparing the same thing here. What BackgroundWorker does is allow your code to run asynchronously, which simplistically means that the computer will allocate time to run the code on a different thread. This means that there is no guarantee when the code in the async side runs - or completes.
When you run the code on the primary thread, then all the time that your program is running this section of code is allocated to it (assuming you haven't created any other threads), but you will block the primary thread here. I would suggest that you have a read about threading, and investigate the Task classes that make asynchronous code a lot easier.
|
|
|
|
|
It looks like I had this question post twice. I put a response on the other one. That would be great if we could switch the primary discussion to the other posting. Thanks!
|
|
|
|
|
Maybe the problem is with how I create the backgroundWorker. From my form class, I am doing the following (I create two of these..one for each form tab):
if (!backgroundWorker1.IsBusy)
{
try
{
backgroundWorker1.RunWorkerAsync();
}
}
Is there a way I can still have the user able to hit a button on the form, yet have the backgroundWorkers hog more of the processor so they can have priority over the form and other things on the computer?
|
|
|
|
|
Not with a background worker - the whole point is that it's meant to work in the background. If it has a higher priority, then this would slow down your application and will lead to a poor user experience.
|
|
|
|
|
I created a class so I can add extensions to the GroupPrincipal object but I am getting this error:
System.InvalidOperationException: Principal objects of type CloudPanel.AD.Custom.GroupPrincipalExt can not be used in a query against this store. at System.DirectoryServices.AccountManagement.ADStoreCtx.GetObjectClassPortion(Type principalType) at System.DirectoryServices.AccountManagement.ADStoreCtx.FindPrincipalByIdentRefHelper(Type principalType, String urnScheme, String urnValue, DateTime referenceDate, Boolean useSidHistory) at System.DirectoryServices.AccountManagement.ADStoreCtx.FindPrincipalByIdentRef(Type principalType, String urnScheme, String urnValue, DateTime referenceDate) at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate) at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, IdentityType identityType, String identityValue) at CloudPanel.AD.Custom.GroupPrincipalExt.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue) at CloudPanel.Exchange.ExchPs.Get_DistributionGroup(String distinguishedname)
I don't really know why this isn't working since I have used this class before.
Here is a piece of the class I created (I didn't include all the DirectoryProperties since there are a bunch that I've added):
public class GroupPrincipalExt : GroupPrincipal
{
public GroupPrincipalExt(PrincipalContext context) : base(context) { }
public GroupPrincipalExt(PrincipalContext context, string groupName) : base(context, groupName) { }
public static new GroupPrincipalExt FindByIdentity(PrincipalContext context, string identityValue)
{
return (GroupPrincipalExt)FindByIdentityWithType(context, typeof(GroupPrincipalExt), identityValue);
}
public static new GroupPrincipalExt FindByIdentity(PrincipalContext context, IdentityType identityType, string identityValue)
{
return (GroupPrincipalExt)FindByIdentityWithType(context, typeof(GroupPrincipalExt), identityType, identityValue);
}
[DirectoryProperty("wWWHomePage")]
public string WWWHomePage
{
get
{
if (ExtensionGet("wWWHomePage").Length != 1)
return null;
return (string)ExtensionGet("wWWHomePage")[0];
}
set
{
this.ExtensionSet("wWWHomePage", value);
}
}
}
Here is how I am calling it:
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "dc.******.local", "DC=*****,DC=local", ContextOptions.SimpleBind, "******\\Administrator", "*********"))
{
GroupPrincipalExt group = GroupPrincipalExt.FindByIdentity(pc, IdentityType.DistinguishedName, distinguishedname);
if (group != null)
{
}
}
Any idea why this would be happening?
|
|
|
|
|
Have you tried adding the DirectoryObjectClassAttribute[^] to your GroupPrincipalExt class?
[DirectoryObjectClass("group")]
public class GroupPrincipalExt : GroupPrincipal
{
...
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Ahhh!! You are awesome. I copied and pasted the class and didn't copy it!
That fixed it. Thank you so much
|
|
|
|
|
Does anyone know a mathematical formula (which can be translated to C #) to check if a polygon is inside another polygon?
|
|
|
|
|
Regular polygons (where all the angles or equal) or irregular?
Needless to say, irregular ones are the PITA...especially where they are the containing polygon.
Just to confirm how much of a PITA irregular polygons are, here's a discussion that may may like to read (though you'll probably wish you hadn't)
The Polygon Containment Problem[^]
modified 28-Jan-13 14:17pm.
|
|
|
|
|
There are irregular polygons.
|
|
|
|
|
If polygon A is inside polygon B, then:
1. Every vertex of A will be inside B, and
2. No edge of A will intersect an edge of B.
So you need two subroutines: One to detect if a point is in a polygon, and one to detect if two line segments intersect each other.
Test all points of A to see if they're in B. If one isn't, then B doesn't contain A. Then test all edges of A to see if any intersect an edge of B. If none do, then polygon A is inside polygon B.
|
|
|
|
|
Yes you are right, but this is a very costly routine, and it might be performed more than 1000 times during the opening of a shapefile.
|
|
|
|
|
So you need efficiency too. Ok, calculate the bounding rectangles of both polygons. If the bounding rectangles don't overlap, neither polygon contains the other, so you can skip the more expensive test.
If they do overlap, check if each polygon contains points of the other in the overlap region. If polygon B contains some points of polygon A, but not others, then B doesn't contain A.
|
|
|
|
|
Hello ,
I am posting on the server side application using a "Response.Write(str)" statement, where "str" contains some XML code .
On the client side I am getting the response using a HttpWebResponse .
When I get the HttpWebResponse content , I find , apart from the correct XML code that I posted on server side, soem kind of strange trailer which resembles an Html page, but is absolutely random (I mean , this "html page" changes from session to session...) .
What is the reason of this strange result ? I am posting some relevant code below to help explain :
Server side :
Resp = ....some XML code ....
Response.Write(Resp);
Client side :
HttpWebRequest WR = (HttpWebRequest)(WebRequest.Create(url));
HttpWebResponse Resp = (HttpWebResponse)WR.GetResponse();
Stream RS = Resp.GetResponseStream();
StreamReader SR = new StreamReader(RS);
string mess = SR.ReadToEnd();
Resp.Close();
textBoxResponse.Text = mess;
Thank you in advance
Leo
|
|
|
|
|
I'm guessing that you're calling Response.Write from the code-behind of an ASP.NET page? In which case, the content of the page will still be output to the response after the text you've passed to the Response.Write method. You'll need to call Response.End after your last call to Response.Write to prevent this.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I followed your instructions and now it works correctly.... I think I need to study better the way a web application works ....
Thank you very much.
Leo
|
|
|
|
|
Hi,
I have a question: I am want to add text (many strings) into file by using the method TextWriter.Write(), will this method append text into a file or overwrite the content of file ?
Are there any other ways to append text into file ?
Thanks and regards,
|
|
|
|
|
A writer will write its content at the current file location, and move the current location to the end of the written content. In typical usage this means that it will append each time you call it.
|
|
|
|
|
Using a StreamWriter [^] is generally a better choice. When you open the underlying FileStream you can specify whether to append or not by the mode option[^].
|
|
|
|
|
The TextWriter don't care. The state of the underlying Stream is what matters -- it can be opened to append or overwrite.
|
|
|
|
|
Thanks all of you.
I used StreamWriter for this.
Kind regards,
|
|
|
|
|
Hi All,
I have created an asp.net c# website that is being used like a helpdesk, tickets are being logged and resolved etc.
I now want to add a pop up that should appear on the user that logged the tickets' pc when the IT personnel updates the ticket.
I am not sure how or if you can use notifyicon to do this?
|
|
|
|