|
Sascha Lefèvre wrote: I try to avoid making use of the expression-character of an assignment. There is something about that usage that gives me a sense of "spooky action at a distance"
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it. A few hundred years later another traveler despairing as myself, may mourn the disappearance of what I may have seen, but failed to see.» Claude Levi-Strauss (Tristes Tropiques, 1955)
|
|
|
|
|
I am using a DataRow to get and set values (based on the manually typed data table from How to Manually Create a Typed DataTable[^]. The fields in the datarow can have different attributes that I would need to track, the main one being a maximum number of characters for some strings, but different versions have different lengths. I was trying to use Attributes to help with this, but I am stuck with how to be able to set/determine the 'version' when going through the attributes. I'd like to be able to set the version on the dataset as a whole and have the fields of the data row be able to use that to determine how to get values.
Here's how I setup my attribute class:
[AttributeUsage(AttributeTargets.Property, AllowMultiple =true)]
public class MaxLengthAttribute : Attribute
{
public string Version;
public int MaxLength;
public MaxLengthAttribute(string version, int max)
{
Version= version;
MaxLength = max;
}
} Here's what the data row looks like and how I am envisioning this would work.
public CustomerRow : DataRow
{
[MaxLength("1.0", 40)]
[MaxLength("2.0", 45)]
public string Name
{
get
{
if(base["Name"] == DBNull.Value) throw new NullException("Name is null.");
return ((TruncatedString)base["Name"]).Value;
}
}
} I created a class called TruncatedString that has a string and bool, which i am using as the data type for the field in the data row. In the TruncatedString I am trying to get the version of the data set and the max length attribute to find out how long my field can be:
public class TruncatedString
{
public bool AutoTruncate;
private string _Value;
public string Value
{
get
{
if(AutoTruncate)
{
int maxLength = ???
if(maxLength >= 0 && Value.Length > maxLength) return _Value.Substring(0, maxLength);
}
return _Value;
}
set { _Value = value; }
}
}
I am not sure if Attributes are the best way to go with this setup, but I do need to be able to store the untruncated string as well as a way to get the truncated but be able to have different lengths for different versions. I also want to be able to do other attributes, for example a field that was added in version 2.0 but not available in 1.0.
|
|
|
|
|
Preprocessor and compiler directives are one way of accomplishing what you want:
#if (C# Reference) | Microsoft Docs
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Few days back, I went for an interview. They just asked me to write code for reversing the array without using Array.Reverse() method. So, here I am sharing the code that might help someone.
for (int i=0; i<arr.Length / 2; i++)
{
int temp = arr[i];
arr[i] = arr[arr.Length – i – 1];
arr[arr.Length – i – 1] = temp;
}
Please let me know if there's any other way to do this. Thanks
|
|
|
|
|
Another way is to decompile the System-assembly which contains the method and copy that implementation into a new method to make up for the missing Array.Reverse() method. Alternative, I would use Enumerable.Reverse as an array is just another enumerable.
No, not the answer the interviewer is wanting, but correct nonetheless and the answer is at least equally valuable as the question
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: decompile the System-assembly
Or just go directly to the source code: Reference Source[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello,
Here is my problem: I am developping a game engine in C # (Winform). The program icon is correctly managed. I want to modify this icon, once the program launched, dynamically, to reflect the choice of the game that has just taken place. The process is done correctly, EXCEPT that it only works if the executable has been launched directly. On the other hand, if the launch was made from a shortcut, (choice in the Start Menu, for example, or redirection icon on the desktop), the icon in the taskbar remains obstinately blocked on the program icon. I tested this program under XP, where it reacts to my convenience (dynamic change of the correct icon) and under W7 or W10 where the update of this icon does not happen.
Here is the code that I use for this function:
try
{
Bitmap b = null;
b = new Bitmap (Fen.Chm + Fen.Gam + "\\" + f);
IntPtr p = b.GetHicon ();
Icon = Icon.FromHandle (p);
b.Dispose ();
}
catch (Exception x)
{
MessageBox.Show (x.Message);
}
I could not find the solution on any site I visited. Does anyone have a track?
|
|
|
|
|
i need a concept that i want to develop a winform apps which will be running as invisible apps in windows OS. when some one try to stop this apps from task manager then a password dialog box will appear. if user could provide right password then apps will be stored or otherwise apps will not be stopped.
please share the idea to show dialog box when user try to stop my apps from task manager.
|
|
|
|
|
MyDialogForm mf = new MyDialogForm();
if (mf.ShowDialog() == DialogResult.OK)
{
string input - mf.UserInputString;
...
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
modified 16-Oct-17 14:19pm.
|
|
|
|
|
Sounds like a great way to get your application classified as "malware".
If you control the computer, then write a Windows service. Only users in the local Administrators group will be able to stop it.
If you don't control the computer, then you have no right to prevent the user from terminating your application. After all, it's their computer, not yours.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
(Not a question, not a Tip/Trick in my eyes. Wanted to share and didn't see a better place for it.)
I'm implementing a write-ahead log (WAL) for an application and was searching for an answer on how to make sure a file actually gets written to disk when I close the FileStream and doesn't linger in one of the intermediary I/O caches, being vulnerable to system power loss.
There's a lot of confusion "in the webs" about which way is actually working:
- FileOptions.WriteThrough / FILE_FLAG_WRITE_THROUGH
- FileStream.Flush(flushToDisk: true)
- Win32.FlushFileBuffers
I was about to ask here when I finally found this:
Revised notes on the reliability of FlushFileBuffers – The Old New Thing[^]
tl;dr: FlushFileBuffers is the way to go on Windows 8 and newer (also best bet on Win7), FileOptions.WriteThrough might work as well but probably not, blame the storage device manufacturers.
Looking into the source of FileStream (.NET 4.7) I saw that all FileStream.Flush(flushToDisk: true) actually does is to call Win32.FlushFileBuffers. On my Google journey I found "hints" that this might not always have been the case, so if you need it, you should look into the source of the .NET version you're using.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
hi,
how can i add voipsdk.dll to reference? i can't find it where the ozeki voip sdk has been installed
|
|
|
|
|
Try reinstalling the SDK, but this time pay attention to where it goes.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I have a class named train ...it has members like train no,trainname etc...i want to create instances of the class at runtime...for each instance new task has to be created and started....
Please guide me to start individual task for each instances when they are created dynamically.
|
|
|
|
|
In your class constructor, add a thread.
The simplest way to do that is to use the BackgroundWorker Class (System.ComponentModel)[^] as it provides a simpel mechanism for communicating with the original thread if necessary.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
A Windows Service uses too many threads. I added some logging to find out more. Sadly, there's little support from the .Net framework.
ThreadPool.GetAvailableThreads(out workerThreads, out completionPortThreads); starts with some 32760 workerThreads, and 1000 completionThreads, resp.
After a few hours, workerThreads went down to 31817, i.e. almost 1000 managed threads are in use. What are they doing? There's no way to find out (you may find some workaround where you place the threads you create into some collection, and later analyze that collection, but that fails when you also use Parellel.ForEach or Task.Run ).
Well, there is another possibility. Try ProcessThreadCollection currentThreads = Process.GetCurrentProcess().Threads; That will give you a list of non-manged threads .
That Windows Service starts with some 20 of them. After a few hours, I detect 3828, i.e. about 4 non-managed threads for each managed thread...
Now I can ask each of them when it started, what is its priority, what it is doing currently, and why it is waiting. Yes, for almost all of them the current state is Wait . And the WaitReason is in most cases UserRequest .
So my question is: what are those threads actually doing? There is no User Interface, even no command line associated with that executable: it is a Windows Service...
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
I want to run an exe or two from inside a windows form. now, i have found a few examples of these on this board, but, I want to be able to keep the exe inside the boundary of the actual form I create in C#. I am using Visual Studio 2013.
thanks very much for your help,
Kevin Rea
Lancaster, Calif. USA
|
|
|
|
|
Perhaps you want to look into the MDI (Multiple-Document Interface), this will load the form "inside" the form. The core concept is to load multiple documents inside the window, and they each run inside their own window.
How to load a form inside another form in C# 2008?
However, if you wanted something like a UserControl type object that mimics the WinForm and display a complete Form object, that I am unsure that you can do. That might be possible through Page , or Window object in WPF to be hosted inside a Frame , but I am unsure as to whether WinForms technology had that much abstraction.
These may help you out a bit more,
Hosting of MFC MDI Applications from Within WinForms and WPF Applications
Windows Forms Controls and Equivalent WPF Controls | Microsoft Docs (Use this to check which controls can be used in which context as alternatives)
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Putting a WinForm inside another WinForm is a mistake.
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it. A few hundred years later another traveler despairing as myself, may mourn the disappearance of what I may have seen, but failed to see.» Claude Levi-Strauss (Tristes Tropiques, 1955)
|
|
|
|
|
BillWoodruff wrote: Putting a WinForm inside another Using WinForm is a mistake. FTFY.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
It is not clear to me what you are trying to do.
An EXE can do anything. It can be a Windows service, a console application, something without any UI at all, a GUI app (WinForm, WPF, Win32, ...) opening one or more windows in whatever size it pleases.
If it is a console app, then instead of trying to place the console in the correct location you can launch the process with all output redirected to your program. Then you have to read these outputs and put them into one or another text display on your form.
If it is a GUI program of one or another kind you can send messages to it telling it to move/resize the window. Basically you can pump the same messages into it programmatically as it would have gotten if the user is moving/resizing the window. Of course, the window can always choose to say "no".
Not a lot of detail on how to do it, but in case I guessed right on what you are trying to do, at least a starting point for what to google.
|
|
|
|
|
Create the columns dynamicaly
edit ListView columns cells even when they are empty with a textbox that size up to the cell left top right bottom.
is that possible
Help me with this topic Please
DanMor498
|
|
|
|
|
My recommendation would be to consider DataGrid to be used here. DataGrid supports this kind of behavior, all you would need to do in order to change the columns would be to change the data source. Instead of having to manage and maintain a ListView control, and then handle the change yourself, DataGrid can really make things simpler and DataGrid also provides the best suitable control for that data type; combobox for enum, textbox for string, checkbox for bool etc.
However, you did not mention the framework in use (WPF or WinForms), thus I will provide the link for the better framework (WPF), DataGrid Class (System.Windows.Controls). Finally,
danmor498 wrote: even when they are empty with a textbox This is something that I cannot understand. What do you mean, "even when they are empty"? If the TextBox is disabled, enable it and edit it.
Go through this CodeProject article as well, Using the DataGrid Control.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
need to click on it when empty to fill it with data
and it's for WinForms
i have a datagridview that look like a listview it is flikering at each line entry
this is wy the Listview
DanMor498
|
|
|
|
|