|
(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
|
|
|
|
|
How many rows are you adding?
If large, by large i mean thousands I would look at double buffering the DataGridView or even looking a virtual mode.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
A Max of 25 rows for printing facility
it's a time start, description, time end, 3 columns for entering report by hours for agent
Thank you for your time and help. Is there na way for me to send you a image of what it is
|
|
|
|
|
I am trying to get the code below to work, but I can't figure it out. Can someone guide me to solve this issue? The code is ready to be copied to a console application.
using System;
using System.Collections.Generic;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Vehicle<Actions> aCar = new Car();
Vehicle<Actions> anAirplane = new Airplane();
List<Vehicle<Actions>> list = new List<Vehicle<Actions>>()
{
aCar,
anAirplane
};
foreach (var vehicle in list)
{
vehicle.actions.ID = "any";
vehicle.actions.PerformAction();
}
Console.WriteLine("Good");
}
}
public interface IVehicle<TActions> where TActions : IActions
{
TActions actions { get; set; }
}
public class Vehicle<TActions> : IVehicle<TActions> where TActions : Actions
{
TActions _actions;
public TActions actions { get => _actions; set => _actions = value; }
}
public class Car : Vehicle<CarActions>
{
public int Wheels { get; set; }
}
public class Airplane : Vehicle<AirplaneActions> {}
public interface IActions
{
string ID { get; set; }
void PerformAction();
}
public abstract class Actions : IActions
{
public string ID { get ; set; }
public abstract void PerformAction();
}
public class CarActions : Actions
{
int speed;
public override void PerformAction()
{
speed = 50;
}
}
public class AirplaneActions : Actions
{
int Height;
public override void PerformAction()
{
Height = 5000;
}
}
}
modified 11-Oct-17 18:50pm.
|
|
|
|
|
Your car does not implement any actions; would you expect the class to implement those actions? Did any of the vehicles get hurt?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I don't think that's the immediate problem.
|
|
|
|
|
Don't spoil my fun yet; I still need to bring up proper XML-documentation, FXCop and StyleCop
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The Car does implement an action (set the speed value), but that is irrelevant. Bottom line, the Car needs to be a Vehicle and as a vehicle in must be able to perform an action but the action is dependent of the type of vehicle:
Vehicle<Actions> myVehicle = new Car();
Vehicle<Actions> myVehicle2 = new Airplane
myVehicle.PerformActions();
myVehicle2.PerformActions();
|
|
|
|
|
I can get it to work compile this way:
IVehicle<IActions> aCar = (IVehicle<IActions>) new Car();
But it won't run successfully.
And, you'll need to instantiate the actions as well:
IVehicle<IActions> aCar = (IVehicle<IActions>) new Car() { actions = new CarActions() } ;
This just in! Made major changes to your code, but it works.
public interface IVehicle<TActions> where TActions : IActions
{
IActions actions { get; set; }
}
public class Vehicle<TActions> : IVehicle<TActions> where TActions : IActions
{
public IActions actions { get ; set; }
}
public class Car : Vehicle<CarActions> , IVehicle<IActions>
{
public int Wheels { get; set; }
}
public class Airplane : Vehicle<AirplaneActions> , IVehicle<IActions>
{
}
modified 12-Oct-17 0:16am.
|
|
|
|
|
Thanks for the suggestions.
|
|
|
|
|
It looks like you need to use generic covariance:
Covariance and Contravariance in Generics | Microsoft Docs[^]
You'll need to use the IVehicle<T> interface instead of the Vehicle<T> class, since generic covariance doesn't work with classes.
You'll also need to remove the setter for the actions property, since that would break the rules for covariance.
The changes you need:
public interface IVehicle<out TActions> where TActions : IActions
{
TActions actions { get; }
}
public abstract class Vehicle<TActions> : IVehicle<TActions> where TActions : Actions
{
public abstract TActions actions { get; }
}
public class Car : Vehicle<CarActions>
{
public int Wheels { get; set; }
public override CarActions actions { get; } = new CarActions();
}
public class Airplane : Vehicle<AirplaneActions>
{
public override AirplaneActions actions { get; } = new AirplaneActions();
}
...
static void Main(string[] args)
{
IVehicle<IActions> aCar = new Car();
IVehicle<Actions> anAirplane = new Airplane();
List<IVehicle<IActions>> list = new List<Vehicle<Actions>>
{
aCar,
anAirplane
};
foreach (var vehicle in list)
{
vehicle.actions.ID = "any";
vehicle.actions.PerformAction();
}
Console.WriteLine("Good");
}
The sample still won't do anything useful, but it should get you started.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard
That did the trick!
|
|
|
|