我正在使用winsock和TCP.我已将KeepAlive选项设置如下
int aliveToggle = 1;
setsockopt(mySocket,SOL_SOCKET,SO_KEEPALIVE,(char*)&aliveToggle, sizeof(aliveToggle));
Run Code Online (Sandbox Code Playgroud)
但是如何指定Keep aLive时间和间隔?
我正在使用在Windows 7上运行的VC++.
我正在为我的WPF应用程序使用MVVMLight工具包.现在我正在阅读Lauren的MIX 10的演示示例.示例代码在SL中,并使用UnityContainer.MVV MVight工具包为WPF提供的模板不使用unitycontainer概念.如何在WPF中使用UnityContainer.
我现在不知道我的问题是否有意义.我没有看到有关如何使用ViewModelLocator的任何文档.也许有人可以提供Lauren在MIX中使用的Demo样本或WPF版本
我在 PHp 中有一些代码,我试图在 C# 中重做。PHP 代码有类似 fputs($file,serialize($val))
什么可能是点 NET 特别是 C# 等效于 Serialize ???
我有一个.dll用C++编写的动态库(),它导出了一个我想在我的C#应用程序中使用的函数:
int SendText(void* pControl, char* sText);
Run Code Online (Sandbox Code Playgroud)
我怎么能,因为它指向void?
我有一个 Datagrid,双击所选行后,将启动一个编辑屏幕。在此编辑屏幕上,有组合框,其值绑定到网格中的选定行。有时,分配给组合框的值在组合框 itemSource 中不存在,因此组合框上的显示为空,但该值不为空。如果 itemsource 集合中不存在该值,我如何将所选项目的值更新为 null。

在上面的场景中,由于第二个屏幕绑定到第一个屏幕上的 Selected 项,因此 City 的 SelectedValue 是“洛杉矶”,而 Display 是空的。但由于集合中不存在“洛杉矶”,因此 SelectedValue 应为 null。
我在DB中有一个浮点数字段.我的应用程序是WindowsForm.我需要将格式为43.27的文本框中的值转换为double.当我这样做COnvert.ToDouble(txtbox.Text)我得到异常,说输入字符串是错误的格式.如何纠正这个问题
在我的C#应用程序中,我希望更新INI文件中的值.我使用了互操作服务并希望使用该功能WritePrivateProfileString.所以我导入了这样的DLL:
[DllImport("KERNEL32.DLL", EntryPoint = "WritePrivateProfileStringW",
SetLastError = true,
CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
private static extern int WritePrivateProfileString(
string lpAppName,
string lpKeyName,
string lpString,
string lpFilename);`
Run Code Online (Sandbox Code Playgroud)
并在我的函数中使用它像这样:
int result = WritePrivateProfileString(category, key, value, iniFile);
Run Code Online (Sandbox Code Playgroud)
但结果为0且INI文件未更新.我该如何检查错误?
我有以下两个函数可以将字节转换为图像并在 WPF 中的图像上显示
private JpegBitmapDecoder ConvertBytestoImageStream(byte[] imageData)
{
Stream imageStreamSource = new MemoryStream(imageData);
JpegBitmapDecoder decoder = new JpegBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource = decoder.Frames[0];
return decoder;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码根本不起作用。我总是遇到“未找到成像组件”图像未显示的异常。
private MemoryStream ConvertBytestoImageStream(int CameraId, byte[] ImageData, int imgWidth, int imgHeight, DateTime detectTime)
{
GCHandle gch = GCHandle.Alloc(ImageData, GCHandleType.Pinned);
int stride = 4 * ((24 * imgWidth + 31) / 32);
Bitmap bmp = new Bitmap(imgWidth, imgHeight, stride, PixelFormat.Format24bppRgb, gch.AddrOfPinnedObject());
MemoryStream ms = new MemoryStream();
bmp.Save(ms, ImageFormat.Jpeg);
gch.Free();
return ms;
}
Run Code Online (Sandbox Code Playgroud)
此功能有效,但速度非常慢。我想优化我的代码。
我使用 net.tcp 将 WCF 作为 Windows 服务托管。在启动服务时安装 Windows 服务后,我发现该服务已启动和停止。
错误说明为了向服务“MYService”添加端点,必须指定非空合同名称。在 System.ServiceModel.Description.ConfigLoader.LookupContract(String contractName, String serviceName)
我的 OnStart 函数如下
protected override void OnStart(string[] args)
{
try
{
if (myServiceHost != null)
{
myServiceHost.Close();
}
myServiceHost = new ServiceHost(typeof(MYservice));
myServiceHost.Open();
}
catch (Exception ex)
{
log.Error("ONStart", ex);
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
配置文件如下:
<serviceHostingEnvironment minFreeMemoryPercentageToActivateService="10" />
<services>
<service behaviorConfiguration="myServiceBehavior"
name="myNamespace.myTestService">
<endpoint binding="netTcpBinding" bindingConfiguration="netTCPBindingConfig" contract="myNamespace.ServiceInterface.ImyTestService" />
<endpoint binding="mexTcpBinding" bindingConfiguration="" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://10.1.3.69:8523/TestService" />
</baseAddresses>
<timeouts closeTimeout="10:00:10" openTimeout="10:01:00" />
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior …Run Code Online (Sandbox Code Playgroud) 如何使用lambda表达式从List中获取名称等于"john"的人数.我怎样才能创建我的lambda表达式?
List<Persons> persons;
person.Where(p=>p.Name.Equals("John");
Run Code Online (Sandbox Code Playgroud)
现在我要对返回的列表进行计数还是应该嵌套它?
c# ×6
wpf ×3
dllimport ×2
mvvm-light ×2
.net ×1
char ×1
combobox ×1
data-binding ×1
decoder ×1
ini ×1
jpeg ×1
lambda ×1
php ×1
self-hosting ×1
sockets ×1
sql ×1
visual-c++ ×1
wcf ×1
winapi ×1