c# 讀寫檔案時檔案正由另一進程使用,因此該進程無法訪問該檔案,在IO處理上遇到了無法操作的問題。檔案“D:\log.txt”正由另一進程使用,因此該進程無法訪問該檔案。log.txt是一個記錄檔,不定時都可能由另外的程式對它進行日誌記錄寫入操作。今需要對記錄檔讀取出來,顯示在日誌查詢裡,需要用到了IO流。1、 FileStream fs = File.OpenRead(url);StreamReader sr = new StreamReader((System.IO.Stream)fs,
註冊全域熱鍵要用到Windows的API方法RegisterHotKey和UnregisterHotKey。一、聲明註冊熱鍵方法[DllImport("user32.dll")]private static extern int RegisterHotKey(IntPtr hwnd, int id, int fsModifiers, int vk);[DllImport("user32.dll")]private static extern int
C#提示--調用DLL使用C#時不免用調用別的DLL,如WIN32的API和自己以前做的DLL, C#調用DLL很像VB,下面討論的C#調用DLL的方式。 看看下面的例子,示範了怎麼定義DLL函數介面 public class Utility { [DllImport("kernel32", EntryPoint=”CreateDirectory”, CallingConvention=CallingConvention.StdCall] public static extern
using System;using System.Collections.Generic;using System.Windows.Forms;using System.Drawing.Printing;namespace FindPrinterDemo{ public partial class Demo : Form { public Demo() { this.Text= "本機印表機列表";
Socket接收到的byte []要轉換成自訂的struct / 自訂Struct轉換成byte []都相當麻煩用迴圈去轉換太浪費時間了……於是想到用CopyMemory,Google一圈終於搞定下面的代碼是在Snippet Compiler裡編譯通過的C#代碼#region Imports using System; using System.IO; using System.Net; using System.Xml; using System.Text;
class A{ void SS() { ************** };}上面類A存在成員函數SS();此時如下操作都可實現: A * a; A * b =NULL;A * c = new A();a->SS();b->SS();c->SS();上面對SS()的調取都能成功。原因是SS()沒有調取類A中的成員變數,或者說A中沒有成員變數和SS()不是虛函數。當類A修改為如下時class A{ int count = 100; void SS() { **
public class AppConfigHelper { private XmlDocument Doc = new XmlDocument(); private AppDomain Ad = AppDomain.CurrentDomain; public static string AppConfigHelperPath = "";//Ad.SetupInformation.ConfigurationFile public