console-application

Console app takes a long time to exit after finishing work

流过昼夜 提交于 2019-12-24 00:42:20
问题 I have a console app that queries a database and then posts some records to a REST API in a loop (the api does not support batch posting, so I have to loop through each record and post individually, if its relevant). The database access is fast and no issue and so is the api post loop according to the timer I've put in place, however the app itself takes a long time to exit after the work is done. This started happening after I introduced Parallel.Foreach to speed up the posting. Before using

Is it possible to make the same DLL into both a console application and a NuGet dependency?

99封情书 提交于 2019-12-24 00:22:31
问题 I have a project that targets .NET Standard 1.5 that is deployed as several DLLs on NuGet. The project was ported from Java. Inside some of the classes of the project are static Main() methods that are meant to be run from the command line. In .NET Core it seems there are 2 ways to compile a DLL: <OutputType>Exe</OutputType> - compiles into an executable console app (DLL) <OutputType>Library</OutputType> (default) - compiles into a class library (DLL) What I am wondering is there a way to

How to read key/value in xml file

有些话、适合烂在心里 提交于 2019-12-24 00:17:46
问题 I am trying to build a console project which reads an ASP.NET project's web.config file. I need to read a value from the config. I am putting what I want to read from the web.config file. <appSettings> <add key="LogoFrmNumber" value="001"/> <add key="LogoFrmPeriod" value="01"/> </appSettings> I want to read LogoFrmNumber's value like I read regular xml file. How can I read that value. here is my code to read web.config but I am stuck. XDocument doc = XDocument.Load( "c://web.config" ); var

How to sync progress bar with process

我与影子孤独终老i 提交于 2019-12-23 22:22:04
问题 I am currently creating a file copying facility that works on console. There are 3 basic classes that exist within this, the first one is the program itself which takes a source and destination and is as follows: class Program { static void Main(string[] args) { Console.WriteLine("Source:"); string path = Console.ReadLine(); Console.WriteLine("target:"); string target = Console.ReadLine(); Copy newCopy = new Copy(); newCopy.CopyFunction(path, target); Console.ReadLine(); } } The second class

wpf console application not returning to prompt

回眸只為那壹抹淺笑 提交于 2019-12-23 17:04:02
问题 I've got a wpf "console" application with the following application class: public partial class App : Application { [DllImport("kernel32.dll", SetLastError = true)] static extern bool AttachConsole(uint dwProcessId); [DllImport("kernel32.dll", SetLastError = true)] static extern bool FreeConsole(); const uint ATTACH_PARENT_PROCESS = 0x0ffffffff; protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); AttachConsole(ATTACH_PARENT_PROCESS); Console.WriteLine("test1");

How to initialize and load MCR

痞子三分冷 提交于 2019-12-23 16:43:38
问题 I incorporated C++ shared library generated from MATLAB in a Win32 console application. The MATLAB program takes 2-3 sec to execute in MATLAB but the console application takes 11-12 seconds to execute. I read this is because of the start up time of MCR and I believe after the MCR is initialized it must take same time as it takes in matlab. So how can I load or initialize the MCR so that it is always in the RAM or cache so that it will take 2-3 sec for the console application to run? Should I

'The file is corrupt and cannot be opened' OpenXML

余生颓废 提交于 2019-12-23 13:58:17
问题 I got that code from OpenXML sdk and instead of SpreadsheetDocument.Create , I used SpreadsheetDocument.Open This code is working and add an image in .xlsx , after image added to the file. I open the file which shows -> The file is corrupt and cannot be opened If you want more details Please! let me know. Reference URL -> https://code.msdn.microsoft.com/office/How-to-insert-image-into-93964561 Thanks for the help! /// <summary> /// add sheet in xlsx then add image into it. /// </summary> ///

Greek letters in Windows Concole

耗尽温柔 提交于 2019-12-23 10:06:24
问题 I'm writting a program in C and I want to have Greek characters in the menu when I run it in cmd.exe . Someone said that in order to include Greek characters you have to use a printf that goes something like this: printf(charset:IS0-1089:uffe); but they weren't sure. Does anyone know how to do that? 回答1: Assuming Windows, you can: set your console font to a Unicode TrueType font: emit the data using an "ANSI" mechanism This code prints γειά σου : #include "windows.h" int main() {

Call a non-static class with a console application

℡╲_俬逩灬. 提交于 2019-12-23 09:26:02
问题 I'm trying to call a method from another class with a console application. The class I try to call isn't static. class Program { static void Main(string[] args) { Program p = new Program(); var myString = p.NonStaticMethod(); } public string NonStaticMethod() { return MyNewClass.MyStringMethod(); //Cannot call non static method } } class MyNewClass { public string MyStringMethod() { return "method called"; } } I get the error: Cannot access non-static method "MyStringMethod" in a static

Shutdown event for console application C#

感情迁移 提交于 2019-12-23 08:53:18
问题 How can i know when my C# console application will be stopping? Is there any event or like that? Thanks! 回答1: Use ProcessExit event of the application domain class Program { static void Main(string[] args) { AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); } static void CurrentDomain_ProcessExit(object sender, EventArgs e) { Console.WriteLine("exit"); } } 回答2: Handling the event System.Console.CancelKeyPress might help you. MSDN explains it how to handle