|
'A long time' is a few milliseconds and 1MB is trivial on a machine with gigabytes to play with. As long as you're using them to actually do something useful, the overhead of starting a thread is irrelevant compared to the time and memory actually processing data. They are 'expensive' on one scale, but in terms of real applications on a typical desktop or server configuration, as long as you don't go nuts (hundreds), they're so cheap it doesn't matter.
If you start dealing with mobile or embedded devices then yes, it suddenly becomes something you must think carefully about again.
|
|
|
|
|
If you're spinning up a few threads, sure, it doesn't really matter.
But when noob's start spinning up a couple of hundred of them, or create threads that take longer to spin up than the code they're executing, or start cranking out threads out of a loop, the costs escale dramatically.
Me, I know enough to use threads out the pool or start up just enough to do the job and recycle them myself.
and not every machine has GBs of RAM to play with. Most of the machines around here where I work are 512MB.
|
|
|
|
|
Then I think we agree . (My initial answer said 'cheap is relative, don't start 200' because yeah, that's dumb.) I think it's better to have a thread pool that is possibly too big by a factor of 2 or so (i.e. 15-20 on an 8 core machine) than risk not making use of all the cores you want, if it's the kind of app where you'd be asking about optimising that number instead of letting the framework pick a good one.
|
|
|
|
|
Yeah, we're on the same page.
I've seen crap code where they're launching thread after thread after thread (one per record!) and wondering why the app performs like crap or ends up crashing the machine entirely.
I tend to preach an over-abundance of caution around here (where I work) when helping people with their code. Spawning/Using a new thread/threadpool should be the last thing you think of if you want your code to run faster.
|
|
|
|
|
Ok, my first time here, don't kill me if I posted in the wrong forum. Anyway.
I have two questions, both regarding sorting a grid in my MVC3 application.
This is what my grid looks like (column names are in swedish):
@(
Html.Grid<ContactListItem>(Model.Contacts)
.Sort(Model.GridSortPageOptions)
.Columns(column =>
{
column.For(x => x.Id).Named("Id").SortColumnName("Id");
column.For(x => x.FirstName).Named("Förnamn").SortColumnName("FirstName");
column.For(x => x.LastName).Named("Efternamn").SortColumnName("LastName");
column.Custom(x =>
{
if (x.Company == null) return "Oknuten kontakt";
else return Html.ActionLink(x.Company.CompanyName, "Show", new { controller = "Company", id = x.Company.Id });
}).Named("Företag").SortColumnName("CompanyName");
column.For(x => x.MobilePhone).Named("Mobil").Sortable(false); ;
column.For(x => x.Telephone).Named("Telefon").Sortable(false); ;
column.For(x => x.Email).Named("E-post").Sortable(false); ;
column.For(x => x.IsContactPerson ? "X" : "").Named("Kontaktperson").SortColumnName("IsContactPerson");
column.For(x => x.IsInvoiceReference ? "X" : "").Named("Fakturareferens").SortColumnName("IsInvoiceReference");
column.For(x => Html.ActionLink("Ändra", "EditContact", new { controller = "Contact", contactId = x.Id, caller = "contactlist" })).Named("Ändra").Sortable(false);
})
)
1) As you might figure, "Company" is a sub property of Contact. When I sort on the Company field, it automatically sorts on the ID property of Company. However, I want it to sort based on the name of the company. How can I use SortColumnName for this? Is it even possible? If it is of any importance, I use Fluent NHibernate. A quick solution would be to add an additional property ("CompanyName") to my domain object, but that would be REALLY ugly.
2) When I hit one of the column names in order to sort, a new label appears next to the column name, saying "(asc)" or "(desc)", depending what way it sorts the items. I would like to be able to change this text to either an other language or to an image (like a tiny arrow pointing up/down).
Thank you!
Edit: spelling >_>
/Erik
What does Abraham mean?
modified on Tuesday, July 26, 2011 6:13 AM
|
|
|
|
|
Ok, so, my second question was answered by a colleague. Simply, these two lines had to be located:
thead th.sort_asc a:after {content: " (asc) ";}
thead th.sort_desc a:after {content: " (desc) ";}
The css property "content" confused me since I had never seen it before. Neither "(asc)" or "(desc)" would show up in the page source in the web browser and I couldn't find it using the developer tools in Chrome. However, the content property is handy and I could simple change the asc/desc text to utf8 arrow symbols
Question no.1 remains unsolved. I think I will have to do quite a bit of hacking to solve it. If I solve it before someone else I'll post my findings here.
Edit: spelling again..
What does Abraham mean?
|
|
|
|
|
Hi,
I'm trying to add new group,
but getting an error:
error (0x80005000)
this is my code-
<br />
public GroupPrincipal CreateNewGroup(string sOU, string sGroupName, <br />
string sDescription, GroupScope oGroupScope, bool bSecurityGroup)<br />
{<br />
PrincipalContext oPrincipalContext = GetPrincipalContext(sOU);<br />
<br />
GroupPrincipal oGroupPrincipal = new GroupPrincipal(oPrincipalContext, sGroupName);<br />
oGroupPrincipal.Description = sDescription;<br />
oGroupPrincipal.GroupScope = oGroupScope;<br />
oGroupPrincipal.IsSecurityGroup = bSecurityGroup;<br />
oGroupPrincipal.Save();<br />
<br />
return oGroupPrincipal;<br />
}<br />
<br />
public PrincipalContext GetPrincipalContext(string sOU)<br />
{<br />
PrincipalContext oPrincipalContext = <br />
new PrincipalContext(ContextType.Domain, sDomain, sOU, <br />
ContextOptions.SimpleBind, sServiceUser, sServicePassword);<br />
return oPrincipalContext;<br />
}<br />
The code thaken from here-
Everything in Active Directory via C#.NET 3.5 (Using System.DirectoryServices.AccountManagement)[^]
i think the error comming from here-
GroupPrincipal oGroupPrincipal = new GroupPrincipal(oPrincipalContext, sGroupName);<br />
what i'm doing wrong?
|
|
|
|
|
You should have received an associated error message. Post it here.
|
|
|
|
|
System.DirectoryServices.AccountManagement.PrincipalOperationException was caught
Message=Unknown error (0x80005000)
Source=System.DirectoryServices.AccountManagement
ErrorCode=-2147463168
|
|
|
|
|
This[^] discussion seems to be related to your problem.
|
|
|
|
|
Chances are you passed in an invalid ADS pathname to one of your functions.
|
|
|
|
|
nope,
all of them ar currect
|
|
|
|
|
Hi,
I am new to this forum, I am a User and Contributer to the C++/MFC Forum. I have written ( and am still writing and maintaining) a suite of Major Applications in C++ 5.00 and MFC42. (I know It's Old, but it meets my and my clients needs emminently, so Why Change).
I am now faced with C# and Framework Code, doing the Movie Tutorial (at least it isn't 'Scribble for NET'(Don't tell me it does actually exist)) and try to make sense of what it generates.
I found the Statement:
public string NewPassword { get; set; }
What on earth does it mean, and how does it fit in the Language.
It is also totally unclear to me which part of an operation is executed on the Server, and which on the Client, or how to control this. Microsoft Priority seems to be that it is 'Seamless'. This is good from an End User of the site point of view, but Not Good from a designer perspective.
I understand that #include is out in C#,actually the whole C-Pre-processor is out, which robs me of a number of well tried and tested debugging methods.
Global Variables are out to, but, there is something called a 'namespace'
I understand sofar, that a 'namespace' is a class declaration/definition( that seems to be forced to be the same too, Everything is 'inline'))
So there appears to be some outermost scope, which acts as 'FileScope' but to which I cannod add.
The Third question is, does the framework code generated by 'Visual Web Developer 2010 Express' keep track of internet Session Status, or do I have to write substantial code myself to ensure that the database the site is using is:
-Aware of Other Users
-Arbitrates between DB Updates
-Remains consistent
Any help is appreciated.
Regards
Bram van Kampen
|
|
|
|
|
Bram van Kampen wrote: I found the Statement:
That there is an auto-implemented property[^] -- very handy.
Bram van Kampen wrote: the whole C-Pre-processor is out
(Pssst... you can pass your C# through a C preprocessor. I do in certain circumstances.)
Bram van Kampen wrote: 'FileScope'
Not really, but there's global:: .
Bram van Kampen wrote: Session Status
I have no idea; I don't do that Web crap.
|
|
|
|
|
Bram van Kampen wrote: It is also totally unclear to me which part of an operation is executed on the Server, and which on the Client, or how to control this.
Depends on what type of project and what type of code. I assume you are talking about web applications...
ASP.NET and WCF services (and other web services) code runs on the server. There may be javascript that runs on the client. Silverlight code runs on the client.
Controlling this is all about deployment. You need to deploy your server code on a server. Your server code will provide the client with its code as requests are made from clients. For example, ASP.NET will serve up HTML. If there's embedded Silverlight application(s) in the HTML then the Silverlight app will be served up to the client as well.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Long reply coming...
Bram van Kampen wrote:
public string NewPassword { get; set; }
What on earth does it mean, and how does it fit in the Language.
It create a property with get/set accessors. There will be some code auto-generated by C# to fill in the bodies for get/set. Since you're a C++ guy, you can think of that line automagically creating the following (hopefully familiar) C++ code:
private: string m_NewPassword;
public:
string get_NewPassword() {
return m_NewPassword;
}
string set_NewPassword(string Value){
m_NewPassword = Value;
}
It is also totally unclear to me which part of an operation is executed on the Server, and which on the Client, or how to control this.
I assume this is a Web Site/App. All C# is always executed on the server. Client browsers are only guaranteed to understand XML, X/HTML, CSS, JavaScript/ECMAScript (probably more). This line can get blurred due to auto-wiring up events, AJAX calls back to the server, runat="server" on script tags, etc. If you give examples, we can probably help better show what executes where.
I understand that #include is out in C#,actually the whole C-Pre-processor is out, which robs me of a number of well tried and tested debugging methods.
File includes are handled in VS as you add/remove them from the project. The .csproj file maintains a list of the file included (can be visually inspected by opening it in a text editor). There's no separation of definition and code, so there's no C# equivalent of header files. There is still extremely basic preprocessor directives, but only to the extent of what's described at C# Preprocessor Directives[^]. As for debugging, you can look into the System.Diagnostic[^] namespace to see if it will suit your needs (or at least help create a replacement for what you're used to).
Global Variables are out to, but, there is something called a 'namespace'
Namespaces are pretty much the same as C++ namespaces. There's no double-colon notations, and everything is dot-qualified. You declare a full namespace in a single line, or you can declare them individually for nested namespaces. The following are equivalent:
namespace A.B.C {
public class X {
}
}
namespace A {
namespace B {
namespace C {
public class X {
}
}
}
}
As you had said, there are no global-scope variables/constants. However, a workaround can easily be achieved by wrapping your 'globals' into a static class like so:
public static class GlobalVars {
public static int global_counter = 0;
public static string global_string = "Yep.";
}
The Third question is, does the framework code generated by 'Visual Web Developer 2010 Express' keep track of internet Session Status, or do I have to write substantial code myself to ensure that the database the site is using is:
-Aware of Other Users
-Arbitrates between DB Updates
-Remains consistent
The web site/app will automatically keep track of sessions for the visitors to the site via a Session state[^] collection on the Page object. However, the sessions are unaware of other sessions currently active on the site. It is more of a collection of objects that are stored on the server (in memory or database) and associated with a received session ID (via cookie/url value). There is an Application collection (System.Web.HttpApplicationState[^]) that does maintain consistency between all site visitors and can share data. You will need to take additional steps to ensure that the read/writes to the Application object are thread-safe (usually via Application.Lock/Unlock).
However, your question about the database maintaining consistency, arbitrating updates, and being multi-user aware is not handled by anything automatically in the web side of things. Database transactions (System.Data.Common.DbTransaction[^]) can be used to help maintain consistency and arbitrate database updates. Making your database code be multi-user aware will likely have to be created by you (depending on what the awareness needs to be).
|
|
|
|
|
I myself and still learning classes in c# 3.0 and I have finally understood the getters and setters to a certain extent.
First you must have an attribute set as private and within its own class. That means that no other method outside of its object can directly change the attribute.
You attribute:
class GetPassword
{
private string _NewPassword;
public string NewPassword
{
get{return this._NewPassword ;}
set{this._NewPassword = value ;}
}
}
private string _NewPassword;
Now outside the class in our main form:
private void button2_Click(object sender, EventArgs e)
{
GetPassword setPassword = new GetPassword();
setPassword.NewPassword = tbSetPassword.Text;
MessageBox.Show(setPassword.NewPassword);
}
Remember when an attribute is set to private in a class, it can not be directly accessed and change by a method outside of the class, so instead the method out side the class 'GetPassword' located in 'Form1' has to access a 'public' method within the class 'GetPassword'. In order to make the change to the private variable. In other words the public string 'NewPassword{}' in 'GetPassword' class, is the public method in this class that can access the private member.
Inside this 'NewPassword{get; set}' method we used the private variable 'this._NewPassword' so this implies and shows the attribute, only this method has access, no other methods. so our method:
setPassword.NewPassword = tbSetPassword.Text;
is actually setting the private member '_NewPassword' by using:
set{this._NewPassword = value ;}
and the button method statement:
MessageBox.Show(setPassword.NewPassword);
Is actually returning the private members '_NewPassword' that had just been set by the user clicking on the button:
get{return this._NewPassword ;}
Sorry if it seems like gibberish but just got off work and trying to leave the building.
modified on Friday, July 29, 2011 5:20 PM
|
|
|
|
|
I have got one question just now can anybody help me?
on the C#,there is value on the any textbox,for exaple textbox1,value is 40,what kind code ı must write to see value of textbox1 on the progressbar1 grafik %40
|
|
|
|
|
Something like progressBar1.Value = int.Parse(textBox1.Text); perhaps?
Of course that will die if you type anything that can't be parsed to an int.
|
|
|
|
|
I'm assuming win forms... You can't draw text on the ProgressBar. There are others around on here that will allow it, have a look here[^]
It's not too difficult to roll your own too!
P.S. Next time, please use a descriptive subject.
|
|
|
|
|
Hi,
Can anyone help me to find Filtering option in columns
I want to know what are the different options for data filtration available for grid supports and which works best in terms of data updating, sorting or any other data related tasks.
|
|
|
|
|
Your question is exceedingly generic. What are you really trying to do?? (And don't say "filter columns") Provider as much detail as possible. "Filtering" can be done in a mirad of ways, but what's "best" depends on what you're doing and how much data you're talking about.
|
|
|
|
|
dessiymartin wrote: what are the different options for data filtration available for grid
None, I'm fairly sure. Filtering can be done by a DataView though. See the DefaultView[^] property of the DataTable class.
|
|
|
|
|
Interesting question.
We can filter rows in a grid by setting filtering conditions via IFilter interface or by directly calling Row.Filtered property.
e.g. setting boolean in the Row.Filtered property and implementing the IFilter interface and setting it with the Grid.Filter property.
This approach covers almost all situations when data filtering may be needed. Filters in column work in parallel with programming filter set via Grid.Filter property. Any of these filters can tell the grid that data should no longer be visible. Have a look if you want to know in detail about data filters in columns
|
|
|
|
|
How can I check if my IIS is alive using C#?
If the server is down - how to do iisreset ?
|
|
|
|
|