|
That's not quite true: it does comment on really dumb code such as:
while (x > 0);
{
...
x--;
} It'll (thankfully) tell you "Possible mistaken empty statement" because of the spurious semicolon. And we've all done that one!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I stand corrected.
However, I believe that there is a big difference between "micro-errors" such as your example (a single character in the wrong place) and criticizing the utility of a whole block of code. At some stage, the compiler must assume that what the programmer wrote is what he/she/it meant.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
If you look at the C# l;anguage specification (it's included with most versions of VS: %Program Files (x86)%\Microsoft Visual Studio x.y\VC#\Specifications\1033 ) the switch is defined as:
switch-statement:
switch ( expression ) switch-block
switch-block:
{ switch-sectionsopt }
switch-sections:
switch-section
switch-sections switch-section
switch-section:
switch-labels statement-list
switch-labels:
switch-label
switch-labels switch-label
switch-label:
case constant-expression :
default : So there is no explicit requirement that the switch expression be variable probably because it would be limiting: you couldn't then use "length - offset", a delegate, or a method instead of the variable because neither of them is a "variable reference" (or in C and C++ an "lvalue"). And what about Properties where the Setter is private or omitted? They are "constants" as well...
Why should that not be a constant? I don't have a problem with that myself - and this from someone whose default project settings are always "Warning Level 4" and "Treat warnings as errors" because the only time it could be confusing is if the value is 0 or 1 and could be mistaken for a single character variable name - which is a bigger crime in my book outside a for-loop control variable!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi,
I have a i5 HDD 2.5ghz 6gb of ram ..
* Visual Studio 08 / 2015 Sql Server Express
* Office
* A few other tools etc ..
My computer can take up to 10mins to boot. I just did a re-install of Win 7 but the updates have me to a crawl again.
I was wondering if anyone has an i7 w/ SSD ??? If so how long does it take for your computer to boot up and get VS 15 running with Sql Express Service etc..
Thinking of getting another computer and trying to figure out how much difference it will make with 256 SSD w/ 6 or 8GB ram ..
Thanks in advance !
|
|
|
|
|
You would have been better asking this in the lounge. This has nothing to do with C#.
This space for rent
|
|
|
|
|
This isn't a C# question, but ...
I have a dual core E6700 based PC @ 3.2GHz with 4GB ram, and a 1TB SSD, running Win10
It boots in under a minute, and loading VS2015 (with a project) takes less than a minute - VS2013 was a lot quicker.
If your SSD is taking 10 minutes to boot Win 7 then that's slow - this computer didn't take that long before I fitted the SSD - but your hardware specs are a load higher than mine! I'd look at what apps you have loaded, or do a malware check. I have heaps of stuff installed, and mine boots at the kind of speed I'd expect.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I agree with OG, and suggest that you run a rootkit/boot sector scan (as you mentioned a re-install). Your computer should have enough beef to boot and run VS properly.
Other likely suspects: BIOS/firmware update required, badly-seated/bad RAM, badly-seated/bad CPU, low voltage off the system power supply.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
wtf32 wrote: My computer can take up to 10mins to boot. I have a i3, 128Gb SSD, 16GB RAM. Boots in less then 10 seconds. Five seconds later, VS2012 is opened. (No VS-addins).
SSD is well worth its price.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
THANKS ALL !
Very useful information !
|
|
|
|
|
1) The Windows Logs will show some of what happens at startup
2) The Services screen will show what services are running; like all the 3rd parties checking for "updates" (including VS and Office)
3) The Startup Tab on the Task Manager will show the "impact" programs that are listed there have at startup (includes 3rd part nonsense and key / screen loggers)
4) The Task Scheduler will list what ran when; which can reveal more 3rd part nonsense that does not show up in Services, Startup or Task Manager (including Google updates; Nero; etc. as well as other MS apps).
5) Anti-virus software is often the biggest performance hog
The challenge is killing off the (bad) zombies.
(Visual Studio 2017 has a "Load me Lite" option that will reduce startups).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
This is a continuation of Winforms custom property fails to reload - edited[^]. I'm moving it here (a) because the question with different things retried was getting too big and complex, and (b) this format allows for better discussion of the issue.
So, I have changed my code so that each Control object implements ISerializable. The property I am trying to populate is a member of my Component derived object and looks like this:
private DialogControls _controls = new DialogControls();
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Editor(typeof(ControlsEditor), typeof(UITypeEditor))]
[Category("Controls")]
[Description("A list of controls that are added to the dialog")]
public DialogControls Controls {
get { return _controls; }
set { _controls = value; }
}
bool ShouldSerializeControls() { return Controls.Count > 0; }
void ResetControls() { Controls.Clear(); Controls.ProminentIndex = -1; }
The ControlGroup and DialogControls objects:
[Serializable]
public class ControlGroup : IList<Control>, ICollection, ISerializable {
public ControlGroup() { }
List<Control> _controls = new List<Control>();
#region IList<Control>, ICollection implementation
#endregion
#region ISerializable
public ControlGroup(SerializationInfo info, StreamingContext context) {
Control[] controls = (Control[])info.GetValue("controls", typeof(Control[]));
_controls.AddRange(controls);
}
public virtual void GetObjectData(SerializationInfo info, StreamingContext context) {
info.AddValue("controls", _controls.ToArray());
}
#endregion
}
[Serializable]
public class DialogControls : ControlGroup, ISerializable {
public DialogControls() { }
public int ProminentIndex { get; set; } = -1;
public Control ProminentControl { get { return ProminentIndex >= 0 ? this[ProminentIndex + 1] : null; } }
#region ISerializable
public DialogControls(SerializationInfo info, StreamingContext context) : base(info, context) {
ProminentIndex = info.GetInt32("prominent");
}
public override void GetObjectData(SerializationInfo info, StreamingContext context) {
base.GetObjectData(info, context);
info.AddValue("prominent", ProminentIndex);
}
#endregion
}
The above is now where the problem occurs. The ControlGroup seems to get serialised, but the individual Control objects do not. Once deserialised, I get an array of nulls.
My Control objects look like this:
[Serializable]
public abstract class Control : ISerializable {
protected const ControlState DefaultState = ControlState.Enabled | ControlState.Visible;
public Control() { }
protected Control(Control other) {
_state = other._state;
}
internal CommonFileDialog _dlg = null;
internal IFileDialogCustomize fdc { get { return (IFileDialogCustomize)_dlg?._pDialog; } }
uint _id = 0;
public uint ID { get { return _id; } internal set { _id = value; } }
protected ControlState _state = DefaultState;
public ControlState State {
get {
fdc?.GetControlState(ID, out _state);
return _state;
}
set {
_state = value;
fdc?.SetControlState(ID, _state);
}
}
internal abstract void AddToDialog(CommonFileDialog owner);
internal abstract bool CanMakeProminent { get; }
internal abstract string Value { get; }
internal abstract string Description { get; }
internal abstract string Type { get; }
public abstract Control Clone();
#region ISerializable
public Control(SerializationInfo info, StreamingContext context) {
_state = (ControlState)info.GetValue("state", typeof(ControlState));
}
public virtual void GetObjectData(SerializationInfo info, StreamingContext context) {
info.AddValue("state", State);
}
#endregion
}
I then inherit each of the controls (there are a dozen of them, but they all follow the same pattern) like this:
[Serializable]
public sealed class CheckBox : Control, ISerializable {
string _label;
public string Label {
get {
return _label;
}
set {
_label = value;
fdc?.SetControlLabel(ID, _label);
}
}
internal bool _checked;
public bool Checked {
get {
return _checked;
}
set {
_checked = value;
fdc?.SetCheckButtonState(ID, _checked);
}
}
public CheckBox() { }
CheckBox(CheckBox other) : base(other) { _label = other._label; _checked = other._checked; }
public CheckBox(string label, bool check) {
Label = label;
Checked = check;
}
#region ISerializable
public CheckBox(SerializationInfo info, StreamingContext context) : base(info, context) {
_label = info.GetString("label");
_checked = info.GetBoolean("checked");
}
public override void GetObjectData(SerializationInfo info, StreamingContext context) {
base.GetObjectData(info, context);
info.AddValue("label", _label);
info.AddValue("checked", _checked);
}
#endregion
#region Control overrides
internal override void AddToDialog(CommonFileDialog dlg) {
}
internal override bool CanMakeProminent { get { return true; } }
internal override string Type { get; } = "CheckBox";
internal override string Description { get { return Label; } }
internal override string Value { get { return Checked.ToString(); } }
public override Control Clone() { return new CheckBox(this); }
public override string ToString() {
return string.Format("{0}({1}, {2})", Type, Description, Value);
}
#endregion
}
Cheers,
Mick
------------------------------------------------
It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.
|
|
|
|
|
I'm not clear on what you "think" you are serializing / deserializing.
You've have "getters" without "setters"; which will never serialize, for example.
And no default constructors (apparently) in some cases; which may be needed depending on the type of serialization.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Yes, all objects do have default constructors, and the serialization does not touch the properties that have the getters without setters - I am only using custom serializers.
It should be serializing an array of objects derived from Control.
Cheers,
Mick
------------------------------------------------
It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.
|
|
|
|
|
I see.
Well, I "love" my xml. My first impulse would have been to try the following:
Designer Serialization Overview
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Ah-ha! Good link. I'd not found that one previously. I'll have a good read, and see if I can get a solution from there.
Ta much.
Cheers,
Mick
------------------------------------------------
It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.
|
|
|
|
|
Another clue:
I modified the ControlGroup serialisation so that it serialises the list of control objects into a byte array, each control being serialised individually, like so:
public ControlGroup(SerializationInfo info, StreamingContext context) {
BinaryFormatter fmt = new BinaryFormatter();
byte[] data = (byte[])info.GetValue("controls", typeof(byte[]));
int count = info.GetInt32("count");
using (MemoryStream ms = new MemoryStream(data)) {
for (int i = 0; i < count; ++i) {
object obj = fmt.Deserialize(ms);
_controls.Add((Control)obj);
}
}
}
public virtual void GetObjectData(SerializationInfo info, StreamingContext context) {
BinaryFormatter fmt = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream()) {
foreach (Control c in _controls) {
fmt.Serialize(ms, c);
}
info.AddValue("controls", ms.ToArray());
}
info.AddValue("count", _controls.Count);
}
When I try to reopen the test form with values set, it tells me that type CheckBox cannot be cast to type Control. However, if I close and reopen VS, or at runtime, it deserialises OK. I even put in a messagebox to tell me if obj is Control - I get "True" on compile, but "False" in designer.
Cheers,
Mick
------------------------------------------------
It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.
modified 18-Jan-17 10:56am.
|
|
|
|
|
In a multi-threaded environment, we must take of concurrent access to writable resources. A common approach is to use Monitor or its shorthand form lock .
Task is at a different abstraction level than Thread . A task may run on a thread of its own (and according to the logs, they do so in our application), but that is not guaranteed. See e.g. c# - What is the difference between task and thread? - Stack Overflow[^]:
If the value you are waiting for comes from the filesystem or a database or the network, then there is no need for a thread to sit around and wait for the data when it can be servicing other requests. Instead, the Task might register a callback to receive the value(s) when they're ready. That is, that kind of Task somehow shares a Thread with other running code (I must admit that I do not understand how that works in detail, currently it looks to me like a specialization of the "famous" DoEvents ).
Consequently, Monitor won't be able to distinguish between them, and - because Monitor can be re-entrant - allow both of them access the resource. That is, Monitor "fails".
Examples with Thread s typically use Monitor nonetheless. So I want to ask how I can be sure that Monitor is safe with a Task (or: how can I be sure that a Task is running on a Thread of its own).
|
|
|
|
|
Well, you could supply a custom TaskScheduler implementation that creates a new Thread every time but that seems to be a bit overkill. Alternatively, you can use the Interlocked class to lock access to whatever needs to be done on a one at a time basis.
private int locked = 0;
private void SomeMethod()
{
try
{
if (Interlocked.CompareExchange(ref locked, 1, 0) != 0)
{
return;
}
}
finally
{
Interlocked.Exchange(ref locked, 0);
}
}
This space for rent
|
|
|
|
|
Thanks for your hints. A custom TaskScheduler is overkill, and would also abolish the advantages of the "normal" scheduler.
As for alternatives, I know that they exist.
|
|
|
|
|
|
That article series looks interesting. I know that there are alternatives to Monitor, but Monitor - or rather the lock statement - is most convenient.
Perhaps I should try a different wording of my original question: why do developers not care for the fact that there seem to be cases when Monitor is not applicable with Task?
|
|
|
|
|
I suspect that some developers don't care enough to know that it doesn't work in every case. That would require them to read up on the topic and think about it - the number of times I have heard someone say that a Task creates a new Thread is beyond belief.
This space for rent
|
|
|
|
|
I have a group of checkboxes that need their values checked on submissions. I can't find a convenient way to group them in MVC. Here's what i have in the markup:
<th>Role:</th>
</tr>
<tr>
<th>Booker:</th>
<td>@Html.CheckBoxFor(m => m.Booker)</td>
<th>OA:</th>
<td>@Html.CheckBoxFor(m => m.OA)</td>
<th>Hauler:</th>
<td>@Html.CheckBoxFor(m => m.Hauler)</td>
<th>DA:</th>
<td>@Html.CheckBoxFor(m => m.DA)</td>
</tr>
<tr>
<th>Booker Only:</th>
<td>@Html.CheckBoxFor(m => m.BAO)</td>
<th>OA Only:</th>
<td>@Html.CheckBoxFor(m => m.OAO)</td>
<th>DA Only:</th>
<td>@Html.CheckBoxFor(m => m.DAO)</td>
Later on, I'm attempting to send a message to the screen letting the user know AT LEAST one of the boxes must be checked:
<script type="text/javascript" language="javascript">
function showDialog() {
var ddlValue = $("#ddlPostingMonth").val();
var ChkBooker = $('#Booker').prop("checked");
var ChkOA = $('#OA').prop("checked");
var ChkHauler = $('#Hauler').prop("checked");
var ChkDA = $('#DA').prop("checked");
var ChkBAO = $('#BAO').prop("checked");
var ChkOAO = $('#OAO').prop("checked");
var ChkDAO = $('#DAO').prop("checked");
alert("This is the value: " + ChkBooker);
if (ddlValue == "")
{ $('#dialog').data("kendoDialog").open(); }
if (ChkBooker,ChkOA == false)
{ $('#dialog').data("kendoDialog").open(); }
else {
$.post('SaveAgentInfo', $('#AgentDetailsForm').serialize(), function (data) {
console.log(data);
});
@*document.location = '@Url.Action("SaveAgentInfo", "Agent", new { master_OrderNum = item.Master_OrderNum })';*@
}
}
I've thrown this around in my mind brand for about an hour. I only need ONE box to be checked!! How can I accomplish this and ignore the other boxes if ONE is checked?
Thanks!
-Frustrated Programmer
|
|
|
|
|
Is it "at least One" or "Only One"?
If only one, consider using Radio Buttons; i.e. only one is "selectable" in a group.
If at least one (and maybe more), consider a multi-select list box; or check boxes (with extra code).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
More than one box can be selected. Guess I'll look into the multi-select list box because I'm about to go crazy dealing with this issue.
|
|
|
|
|