Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 500000; i++)
{
List<string> list = new List<string>();
}
sw.Stop();
Console.WriteLine(sw.Elapsed);
Console.Read();
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 500000; i++)
{
List<string> list = new List<string>();
}
sw.Stop();
Console.WriteLine(sw.Elapsed);
Console.Read();
<system.runtime.remoting> <application name="ScheduleServiceMonitor"> <service> <wellknown type="ScheduleService.Remoting.ServiceMonitor, ServicePlugin" mode="Singleton" objectUri="ScheduleService.Remoting" /> </service> <channels> <channel ref="tcp" port="9876" /> </channels> </application> </system.runtime.remoting>start remoting
RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, false);
Imports System.SerializableAttribute <Serializable()> Public Class TransferFile Public FileName As String Public Data() As Byte End ClassTcpFileReceiver.vb
Imports System.Net.Sockets
Imports System.Net
Imports System.IO
Imports System.Threading
Imports System.SerializableAttribute
Imports System.Runtime.Serialization.Formatters.Binary
Public Class TcpFileReceiver
' 預設寫入檔案資料夾
Public SavePath As String = AppDomain.CurrentDomain.BaseDirectory
' 監聽器
Private fileListener As TcpListener
' 暫存資料
Private tempData As Dictionary(Of String, List(Of Byte))
Public Sub New(ByVal ip As IPAddress, ByVal port As Integer)
Me.fileListener = New TcpListener(New IPEndPoint(ip, port))
Me.tempData = New Dictionary(Of String, List(Of Byte))
End Sub
' 開始監聽
Public Sub Start()
Me.fileListener.Start()
' 建立接收連線的執行緒
Dim listenThread As Thread = New Thread(New ThreadStart(AddressOf DeterminConnection))
listenThread.IsBackground = True
listenThread.Start()
End Sub
' 結束監聽
Public Sub StopListen()
Me.fileListener.Stop()
End Sub
' 偵測client端連接
Private Sub DeterminConnection()
Do
Try
' 如果有連接
If Me.fileListener.Pending Then
' 建立傳輸的執行緒
Dim receiveThread As Thread = New Thread(New ThreadStart(AddressOf StartServerListener))
receiveThread.IsBackground = True
receiveThread.Start()
End If
Catch ex As Exception
' do something
End Try
GC.Collect()
Thread.Sleep(1000)
Loop
End Sub
' 起始傳輸
Private Sub StartServerListener()
Do
Try
' 建立傳輸通道
Dim rSocket As Socket = Me.fileListener.AcceptSocket()
If rSocket.Connected Then
' 接收連線的buffer
Dim rBuffer(1024) As Byte
' 暫存資料的key
Dim rGuid As String = Guid.NewGuid.ToString
' 開始接收
SyncLock rSocket
rSocket.BeginReceive(rBuffer, 0, 1024, SocketFlags.None, AddressOf GetData, New Object() {rSocket, rBuffer, rGuid})
End SyncLock
End If
Catch ex As Exception
Return
End Try
Loop
End Sub
Private Sub GetData(ByVal result As IAsyncResult)
Try
' 目前傳輸的socket
Dim rSocket As Socket = CType(result.AsyncState, Object())(0)
' 接收的資料
Dim rBuffer() As Byte = CType(result.AsyncState, Object())(1)
' 暫存資料的key
Dim rGuid As String = CType(result.AsyncState, Object())(2)
' 如果沒有資料, 建立暫存區
If Not Me.tempData.ContainsKey(rGuid) Then
Me.tempData.Add(rGuid, New List(Of Byte))
End If
' 讀取的總數
Dim readed As Integer = rSocket.EndReceive(result)
If readed > 0 Then
'Dim data As List(Of Byte) = tempData(rGuid)
'For i As Integer = 0 To readed - 1
' Me.tempData(rGuid).Add(rBuffer(i))
'Next
' 存入暫存區
Array.Resize(rBuffer, readed)
Me.tempData(rGuid).AddRange(rBuffer)
' 讀取下一段資料
ReDim rBuffer(1024)
SyncLock rSocket
rSocket.BeginReceive(rBuffer, 0, 1024, SocketFlags.None, AddressOf GetData, New Object() {rSocket, rBuffer, rGuid})
End SyncLock
Else
rSocket = Nothing
rBuffer = Nothing
' 反序列化
Dim transferObj As TransferFile = Me.Deserialize(Me.tempData(rGuid).ToArray)
' 存檔
File.WriteAllBytes(Me.SavePath & transferObj.FileName, transferObj.Data)
' 移除暫存資料
Me.tempData(rGuid).Clear()
Me.tempData.Remove(rGuid)
rGuid = Nothing
' 資源回收
GC.Collect()
End If
Catch ex As Exception
' do something
End Try
End Sub
' 反序列化
Private Function Deserialize(ByRef data() As Byte) As TransferFile
Dim ms As MemoryStream = New MemoryStream(data)
Dim formater As BinaryFormatter = New BinaryFormatter
Dim transferObj As TransferFile = formater.Deserialize(ms)
ms.Close()
Return transferObj
End Function
End Class
TcpFileSender.vb
Imports System.IO
Imports System.Net.Sockets
Imports System.Net
Imports System.Threading
Imports System.SerializableAttribute
Imports System.Runtime.Serialization.Formatters.Binary
Public Class TcpFileSender
Private client As TcpClient
Public Sub New()
Me.client = New TcpClient()
End Sub
Public Function ConnectServer(ByVal ip As IPAddress, ByVal port As Integer) As Boolean
Try
' 連接至server
Me.client.Connect(New IPEndPoint(ip, port))
Return True
Catch ex As Exception
Return False
End Try
End Function
Public Sub CloseConnection()
Me.client.Close()
GC.Collect()
End Sub
Public Sub Send(ByVal filepath As String)
Dim thread As Thread = New Thread(New ParameterizedThreadStart(AddressOf SendFile))
thread.IsBackground = True
thread.Start(filepath)
End Sub
Public Sub SendFile(ByVal filepath As String)
' 檔案不存在
If Not File.Exists(filepath) Then
Throw New FileNotFoundException
End If
' 建立要傳送的物件實體
Dim transferObj As TransferFile = New TransferFile
' 取檔名
Dim inputFile As FileInfo = New FileInfo(filepath)
transferObj.FileName = inputFile.Name
' 讀取檔案
Dim inputStream As FileStream = New FileStream(filepath, FileMode.Open)
ReDim transferObj.Data(inputStream.Length)
inputStream.Read(transferObj.Data, 0, transferObj.Data.Length)
inputStream.Close()
' 序列化
Dim transferData() As Byte = Me.Serialize(transferObj)
If Me.client.Connected Then
' 防止檔案過大, 佇列已滿
While True
Try
Me.client.GetStream.Write(transferData, 0, transferData.Length)
GC.Collect()
Exit While
Catch ex As Exception
Threading.Thread.Sleep(1000)
End Try
End While
Else
Throw New Exception("Not Connected!")
End If
End Sub
' 序列化物件
Private Function Serialize(ByVal obj As Object) As Byte()
Dim ms As MemoryStream = New MemoryStream
Dim formater As BinaryFormatter = New BinaryFormatter
formater.Serialize(ms, obj)
Dim data() As Byte = ms.GetBuffer
ms.Close()
Return data
End Function
End Class
GC.GetTotalMemory(true)If you want to know what your process uses from Windows (VM Size column in TaskManager) try:
Process.GetCurrentProcess().PrivateMemorySize64If you want to know what your process has in RAM (as opposed to in the pagefile) (Mem Usage column in TaskManager) try:
Process.GetCurrentProcess().WorkingSet64See here for more explanation on the different sorts of memory.
Disk /dev/sda: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors/track, 19457 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x9c29f0a3 所用裝置 Boot Start End Blocks Id System /dev/sda1 * 1 3552 28531408+ 83 Linux /dev/sda2 3553 3946 3164805 82 Linux swap / Solaris /dev/sda3 3947 19457 124582912 7 HPFS/NTFS Disk /dev/sdb: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors/track, 19457 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0xd788d788 所用裝置 Boot Start End Blocks Id System /dev/sdb1 1 19458 156288000 7 HPFS/NTFSedit /etc/fstab , append red part
# /etc/fstab: static file system information. # # Use 'blkid -o value -s UUID' to print the universally unique identifier # for a device; this may be used with UUID= as a more robust way to name # devices that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # / was on /dev/sda1 during installation UUID=88f5915d-7654-402e-b7de-9dbb75b27b53 / ext4 errors=remount-ro 0 1 # swap was on /dev/sda2 during installation UUID=6e67ce31-882f-4a5f-aec9-8d6f23fad16f none swap sw 0 0 /dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec,utf8 0 0 /dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0 /dev/sda3 /media/DataSource ntfs defaults 0 0 /dev/sdb1 /media/Images ntfs defaults 0 0
|
參數
|
說明
|
參數
|
說明
|
|
Source
|
原始碼
|
DocProps
|
文件屬性
|
|
Save
|
儲存
|
NewPage
|
開新檔案
|
|
Preview
|
預覽
|
Templates
|
樣板
|
|
Cut
|
剪下
|
Copy
|
拷貝
|
|
Paste
|
貼上
|
PasteText
|
貼為純文字
|
|
PasteWord
|
從 Word 貼上
|
Print
|
列印
|
|
SpellCheck
|
拼字檢查
|
Undo
|
復原
|
|
Redo
|
復原
|
Find
|
尋找
|
|
Replace
|
取代
|
SelectAll
|
全選
|
|
RemoveFormat
|
清除格式
|
Form
|
表單
|
|
Checkbox
|
核取方塊
|
Radio
|
選項按鈕
|
|
TextField
|
文字區域
|
Select
|
下拉選單
|
|
Button
|
按鈕
|
ImageButton
|
影像按鈕
|
|
HiddenField
|
隱藏欄位
|
Bold
|
粗體
|
|
Italic
|
斜體
|
Underline
|
底線
|
|
StrikeThrough
|
刪除線
|
Subscript
|
下標字
|
|
Superscript
|
上標字
|
OrderedList
|
數字項目符號
|
|
UnorderedList
|
項目符號
|
Outdent
|
減少縮排
|
|
Indent
|
增加縮排
|
Blockquote
|
區塊引用
|
|
JustifyLeft
|
靠左
|
JustifyCenter
|
置中
|
|
JustifyRight
|
靠右
|
JustifyFull
|
左右對齊
|
|
Link
|
建立連結
|
Unlink
|
移除連結
|
|
Anchor
|
錨點
|
Image
|
插入圖片
|
|
Flash
|
插入Flash
|
Table
|
插入表格
|
|
Rule
|
插入水平線
|
Smiley
|
表情符號
|
|
SpecialChar
|
特殊符號
|
PageBreak
|
分頁符號
|
|
Style
|
樣式
|
FontFormat
|
字體格式
|
|
FontName
|
字型選擇
|
FontSize
|
字型大小
|
|
TextColor
|
文字顏色
|
BGColor
|
背景顏色
|
|
FitWindow
|
編輯器最大化
|
ShowBlocks
|
顯示HTML標籤區塊
|
|
About
|
關於FCKeditor
|
|
|
Application: BeginRequest Application: PreAuthenticateRequest Application: AuthenticateRequest Application: PostAuthenticateRequest Application: PreAuthorizeRequest Application: AuthorizeRequest Application: PostAuthorizeRequest Application: PreResolveRequestCache Application: ResolveRequestCache Application: PostResolveRequestCache Application: PreMapRequestHandler Page: Construct Application: PostMapRequestHandler Application: PreAcquireRequestState Application: AcquireRequestState Application: PostAcquireRequestState Application: PreRequestHandlerExecute Page: AddParsedSubObject Page: CreateControlCollection Page: AddedControl Page: AddParsedSubObject Page: AddedControl Page: ResolveAdapter Page: DeterminePostBackMode Page: PreInit Control: ResolveAdapter Control: Init Control: TrackViewState Page: Init Page: TrackViewState Page: InitComplete Page: LoadPageStateFromPersistenceMedium Control: LoadViewState Page: EnsureChildControls Page: CreateChildControls Page: PreLoad Page: Load Control: DataBind Control: Load Page: EnsureChildControls Page: LoadComplete Page: EnsureChildControls Page: PreRender Control: EnsureChildControls Control: PreRender Page: PreRenderComplete Page: SaveViewState Control: SaveViewState Page: SaveViewState Control: SaveViewState Page: SavePageStateToPersistenceMedium Page: SaveStateComplete Page: CreateHtmlTextWriter Page: RenderControl Page: Render Page: RenderChildren Control: RenderControl Page: VerifyRenderingInServerForm Page: CreateHtmlTextWriter Control: Unload Control: Dispose Page: Unload Page: Dispose Application: PostRequestHandlerExecute Application: PreReleaseRequestState Application: ReleaseRequestState Application: PostReleaseRequestState Application: PreUpdateRequestCache Application: UpdateRequestCache Application: PostUpdateRequestCache Application: EndRequest Application: PreSendRequestHeaders Application: PreSendRequestContent
/// <summary>
/// Summary description for InputBox.
///
public class InputBoxDialog : System.Windows.Forms.Form
{
#region Windows Contols and Constructor
private System.Windows.Forms.Label lblPrompt;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox txtInput;
/// <summary>
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public InputBoxDialog()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
#endregion
#region Dispose
/// <summary>
/// Clean up any resources being used.
///
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#endregion
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.lblPrompt = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.txtInput = new System.Windows.Forms.TextBox();
this.btnOK = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lblPrompt
//
this.lblPrompt.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblPrompt.BackColor = System.Drawing.SystemColors.Control;
this.lblPrompt.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblPrompt.Location = new System.Drawing.Point(12, 17);
this.lblPrompt.Name = "lblPrompt";
this.lblPrompt.Size = new System.Drawing.Size(303, 22);
this.lblPrompt.TabIndex = 3;
//
// button1
//
this.button1.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button1.Location = new System.Drawing.Point(323, 45);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 27);
this.button1.TabIndex = 2;
this.button1.Text = "&Cancel";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// txtInput
//
this.txtInput.Location = new System.Drawing.Point(8, 78);
this.txtInput.Name = "txtInput";
this.txtInput.Size = new System.Drawing.Size(379, 22);
this.txtInput.TabIndex = 0;
this.txtInput.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtInput_KeyPress);
//
// btnOK
//
this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOK.Location = new System.Drawing.Point(323, 12);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(64, 27);
this.btnOK.TabIndex = 1;
this.btnOK.Text = "&OK";
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// InputBoxDialog
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(399, 111);
this.Controls.Add(this.txtInput);
this.Controls.Add(this.button1);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.lblPrompt);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "InputBoxDialog";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "InputBox";
this.Load += new System.EventHandler(this.InputBox_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
#region Private Variables
string formCaption = string.Empty;
string formPrompt = string.Empty;
string inputResponse = string.Empty;
string defaultValue = string.Empty;
DialogResult clickedButton;
#endregion
#region Public Properties
public string FormCaption
{
get { return formCaption; }
set { formCaption = value; }
} // property FormCaption
public string FormPrompt
{
get { return formPrompt; }
set { formPrompt = value; }
} // property FormPrompt
public string InputResponse
{
get { return inputResponse; }
set { inputResponse = value; }
} // property InputResponse
public string DefaultValue
{
get { return defaultValue; }
set { defaultValue = value; }
} // property DefaultValue
public DialogResult ClickedButton
{
get { return clickedButton; }
}
#endregion
#region Form and Control Events
private void InputBox_Load(object sender, System.EventArgs e)
{
this.txtInput.Text = defaultValue;
this.lblPrompt.Text = formPrompt;
this.Text = formCaption;
this.txtInput.SelectionStart = 0;
this.txtInput.SelectionLength = this.txtInput.Text.Length;
this.txtInput.Focus();
}
private void btnOK_Click(object sender, System.EventArgs e)
{
this.clickedButton = DialogResult.OK;
InputResponse = this.txtInput.Text;
this.Close();
}
private void button1_Click(object sender, System.EventArgs e)
{
this.clickedButton = DialogResult.Cancel;
this.Close();
}
public static string InputBox(string prompt, string title, string defaultValue)
{
InputBoxDialog ib = new InputBoxDialog();
ib.FormPrompt = prompt;
ib.FormCaption = title;
ib.DefaultValue = defaultValue;
ib.ShowDialog();
string s = ib.InputResponse;
ib.Close();
return s;
}// method: InputBox
private Button btnOK;
private void txtInput_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
btnOK_Click(sender, e);
e.Handled = true;
}
}
#endregion
}
class MyThread
{
private int executeInterval = 15;
public int ExecuteInterval
{
get { return this.executeInterval; }
set { this.executeInterval = value; }
}
private int checkFlagInterval = 1;
public int CheckFlagInterval
{
get { return this.checkFlagInterval; }
set
{
this.checkFlagInterval = value < 1 ? 1 : value;
this.checkFlagInterval = value > this.executeInterval ? this.executeInterval : value;
}
}
private bool flag = true;
public bool Flag
{
get { return this.flag; }
set { this.flag = value; }
}
public void Run()
{
int timeout = 0;
while (this.flag)
{
if ((timeout -= checkFlagInterval) < 1)
{
// do something
timeout = this.executeInterval;
}
Thread.Sleep(this.checkFlagInterval * 1000);
}
}
}
class Program
{
static void Main(string[] args)
{
MyThread myThread = new MyThread();
Thread thread = new Thread(new ThreadStart(myThread.Run));
thread.Start();
while (myThread.Flag)
{
myThread.Flag = Console.Read() != 'q';
}
}
}