何时在.NET紧凑框架中分配内存?如果值和参考类型之间存在差异,请详细说明.赞赏文档或确认步骤.
特别要考虑这种情况......
private MyClass item; // here?
public void MyMethod()
{
item = new MyClass(); // or here?
}
Run Code Online (Sandbox Code Playgroud) 我想将一个复选框控件添加到列表框控件.
列表框必须包含几个任务,我必须检查之前是否已打开任务.
我有一个代码示例,但它将复选框添加为对象,而不是控件
while (reader.Read())
{
CheckBox c = new CheckBox().Enabled = false;
c.Text = reader.GetString(0) + ". " + reader.GetString(1);
try
{
if (int.Parse(reader.GetString(2)) > 1) c.Checked = true;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
listTasks.Items.Add(c);
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮我吗
Thnx,鲁本
我有一个运行后台线程来触发事件,但是如何使用NET CF确保线程安全地调用这些事件?
我会在.NET平台上使用ISyncronizeInvoke,但我在NET CF上找不到这个.我敢肯定有一个等效的......或者?
使用C#,我试图在我的Pocket PC应用程序中绘制一个控件实例,比如一个面板或按钮..NET控件具有漂亮的DrawToBitmap函数,但它在.NET Compact Framework中不存在.
如何在Pocket PC应用程序中将控件绘制到图像?
让我们说有一个150字节长的文件,我想截断它的最后16(或任何数字)...
除了重写完整的文件之外还有其他方法吗?
更新: SetLength应该做的事情,但遗憾的是抛出了NotSupportedException
using (FileStream fsFinalWrite = new FileStream(FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
fsFinalWrite.Seek(16, SeekOrigin.End);
fsFinalWrite.Write(SwappedBytes, 0, 16);
Debug.WriteLine("fsFinalWrite Can Seek = " + fsFinalWrite.CanSeek);
Debug.WriteLine("fsFinalWrite Can Write = " + fsFinalWrite.CanWrite);
fsFinalWrite.SetLength((long)lengthOfFile);
}
Run Code Online (Sandbox Code Playgroud)
两者都打印真实!但它仍会抛出NotSupportedException.任何人都知道如何处理这个?
我遇到过一种情况,由于我调用的其他一些代码区域无法复制Dictionary<TKey, TValue>它返回的内容,因此会出现并发问题:Dictionary似乎包含非法的空键.
我已经修复了底层错误,但为了帮助识别这个问题,如果它将来再次出现,我会添加一些代码,在循环中显式检查null键,处理返回的字典并在事情发生之前抛出进一步.我不确定要抛出哪个异常类,或者如果我定义一个新类,我要确定哪个异类.
我正在研究.Net Compact Frmework(CF)应用程序.我这个应用程序的要求是我应该能够更改TimeZone.但是,当我更改TimeZone时,当前时间不会更改为特定的TimeZone.从,我开始知道DateTime.Now在这种情况下无法工作.
我正在使用以下Win API:
SetTimeZoneInformation(...) - 在运行时设置时区.GetLocalTime(...) - 获取当地时间和当前时区.任何人都可以告诉我可能有什么问题吗?
此代码导致某种内存泄漏.我认为它是由...引起的new byte[].但GC不应该避免这种情况吗?如果程序运行的时间足够长,代码将导致OutOfMemoryException
using (var file = new FileStream(fileLoc, FileMode.Open))
{
int chunkSize = 1024 * 100;
while (file.Position < file.Length)
{
if (file.Length - file.Position < chunkSize)
{
chunkSize = (int)(file.Length - file.Position);
}
byte[] chunk = new byte[chunkSize];
file.Read(chunk, 0, chunkSize);
context.Response.BinaryWrite(chunk);
}
}
Run Code Online (Sandbox Code Playgroud) 下面是在紧凑框架3.5中启动线程的方法
public ScanEntry(string scanId)
{
InitializeComponent();
_scanId = scanId;
//reader = deviceFactory.Create();
//reader.YMEvent += new ScanEventHandler(reader_Reading);
//reader.Enable();
}
private void CasesEntry_Load(object sender, EventArgs e)
{
caseCounterLabel.Text = cases.Count.ToString();
scanIdValueLabel.Text = _scanId;
}
internal void menuItemNewScan_Click(object sender, EventArgs e)
{
System.Threading.ThreadStart threadDelegate = new System.Threading.ThreadStart(ScanEvents);
System.Threading.Thread newThread = new System.Threading.Thread(threadDelegate);
newThread.Start();
}
Run Code Online (Sandbox Code Playgroud)
在线程上调用下面的方法
private void ScanEvents()
{
try
{
//some other codes
if (scanIdValueLabel.InvokeRequired)
{
scanIdValueLabel.Invoke((Action)(() => scanIdValueLabel.Text = "value"));
}
attributeNode = docEventFile.CreateNode(XmlNodeType.Element, "Attribute", string.Empty);
XMLUtils.CreateAttribute(docEventFile, attributeNode, "name", "SCANID");
XMLUtils.CreateAttribute(docEventFile, …Run Code Online (Sandbox Code Playgroud) 我的公司正在考虑切换到这些手持设备:https : //www.barcodesinc.com/motorola/part-mc32n0-gi4hcheia.htm#specs 他们从Windows Embedded Compact 7上运行。我受命编写库存管理程序。解。我确实有C#.NET经验,但是没有使用Compact Framework(CF)的经验,所以我有几个问题。
c# compact-framework visual-studio windows-embedded-compact visual-studio-2012
c# ×9
.net ×5
windows-ce ×2
.net-3.5 ×1
checkbox ×1
coding-style ×1
exception ×1
file-io ×1
filestream ×1
listbox ×1
memory ×1
truncate ×1