我编写了以下代码来配置MainForm加载时的串口.在第一次运行时,它会IOException在端口打开时给出,说明参数不正确.但是,当我重新启动应用程序时,它工作正常.只有在启动计算机后第一次运行应用程序时才会出现异常,然后它才能正常工作,直到下次重新启动计算机.
private void Main_Load(object sender, EventArgs e)
{
this.serialPort1.PortName = "COM3";
this.serialPort1.BaudRate = 9600;
this.serialPort1.DataBits = 8;
this.serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort1_DataReceived);
this.serialPort1.Open(); //Exception comes here
this.serialPort1.WriteLine("AT#cid=1" + System.Environment.NewLine);
}
Run Code Online (Sandbox Code Playgroud)
执行细节:
System.IO.IOException未被用户代码处理
Message ="参数不正确.\ r \n"Source ="System"
堆栈跟踪:在System.IO.Ports.InternalResources.WinIOError(的Int32的errorCode,字符串str)在System.IO.Ports.InternalResources.WinIOError()在System.IO.Ports.SerialStream.set_RtsEnable(布尔值)System.IO. Ports.SerialStream..ctor(字符串PORTNAME,的Int32波特率,奇偶校验位,数据位的Int32,停止位停止位,的Int32 readTimeout,的Int32 writeTimeout,握手握手,布尔dtrEnable,布尔rtsEnable,布尔discardNull,字节parityReplace)在System.IO.Ports. SerialPort.Open()在JKamdar.Main.Main_Load(对象发件人,EventArgs e)在d:\项目\ JKamdar\JKamdar\Main.cs:线264处系统System.Windows.Forms.Form.OnLoad(EventArgs的) .Windows.Forms.Form.OnCreateControl()在System.Windows.Forms.Control.CreateControl(布尔fIgnoreVisible)在System.Windows.Forms.Control.CreateControl()在System.Windows.Forms.Control.WmShowWindow(邮件&m)在System.Windows.Forms.Control.WndProc在System.Windows.Forms.ScrollableControl.WndProc在System.Windows(邮件&m)(邮件&m).Forms.ContainerControl.WndProc(消息&m)上System.Windows.Forms.Form.WmShowWindow在System.Windows.Forms.Control.ControlNativeWindow.OnMessage在System.Windows.Forms.Form.WndProc(邮件&m)(邮件&m) (消息&m)上在System.Windows.Forms.NativeWindow.Callback System.Windows.Forms.Control.ControlNativeWindow.WndProc(邮件&m)(IntPtr的的HWND,MSG的Int32,IntPtr的WPARAM,IntPtr的LPARAM)的InnerException:
当有人打电话时,我使用以下方法来检测来电显示.
在表单加载时,我设置以下代码:
this.serialPort1.PortName = "COM3";
this.serialPort1.BaudRate = 9600;
this.serialPort1.DataBits = 8;
this.serialPort1.RtsEnable = true;
this.serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
this.serialPort1.Open();
this.serialPort1.WriteLine("AT#cid=1" + System.Environment.NewLine);
void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
richTextBox1.Text += this.serialPort1.ReadLine();
//richTextBox1.Text += this.serialPort1.ReadExisting();
//richTextBox1.Text += this.serialPort1.ReadByte().ToString();
}
Run Code Online (Sandbox Code Playgroud)
命令
this.serialPort1.WriteLine("AT#cid=1" + System.Environment.NewLine);
Run Code Online (Sandbox Code Playgroud)
给了我输出
OK
Run Code Online (Sandbox Code Playgroud)
这确保了调制解调器支持调制解调器ID并且正在工作.
我在我们国家(印度)试过一些私人电话线,它给出了预期的输出如下.
RING //On 1st Ring
DATE = xxxxx //On 2nd Ring
TIME = xxxx
NMBR = xxxxxxxxx
RING //On 3rd Ring
RING //On 4th Ring
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用政府电话(印度的BSNL公司)时,它没有提供DATE,TIME和NMBR部分.它给出了以下输出.
RING //On 1st Ring
RING //On 3rd Ring
RING …Run Code Online (Sandbox Code Playgroud) 我有下表
CREATE TABLE [dbo].[DeviceLogs](
[DeviceLogId] [int] IDENTITY(1,1) NOT NULL,
[UserId] [nvarchar](50) NULL,
[LogDate] [datetime2](0) NULL,
)
GO
Run Code Online (Sandbox Code Playgroud)
数据样本
1 1 2013-05-29 11:05:15 //accepted (its the first occurance for userid 1)
2 1 2013-05-29 11:05:20 //discarded (within 5 mins from 1st record)
3 1 2013-05-29 11:07:56 //discarded (within 5 mins from 1st record)
4 1 2013-05-29 11:11:15 //accepted (after 5 mins from 1st occurance)
5 2 2013-05-29 11:06:05 //accepted (its the first occurance for userid 2)
6 2 2013-05-29 11:07:18 //discarded …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用DirectX dll播放音频文件.
Audio.FromFile("Message 1.mp3").Play();
Run Code Online (Sandbox Code Playgroud)
但是检测到加载程序锁定异常,如下所示:我不是分析堆栈跟踪的专家.如何分析和解决装载机锁定问题?
检测到LoaderLock
Message: DLL 'C:\Windows\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.dll' is attempting managed execution inside OS Loader lock.
Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
'ToDoApp.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ToDoApp.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\9.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ToDoApp.vshost.exe' …Run Code Online (Sandbox Code Playgroud) 我在文章和MSDN中多次读过float(或double)没有真实世界整数或小数值的精确表示.正确!当得到相等检查错误或者在断言简单的加法或减法测试时,这是可见的.
还有人说float没有像0.1这样的十进制值的精确表示,但是如果我们在visual studio中声明一个float float a = 0.1f;,那么在调试时它们如何显示精确的0.1?它应该显示类似的东西0.09999999...我在哪里可以找到理解它的链接.

这是一个门外汉的问题,或者可能是我仍然缺少一些概念!
我正在寻找交叉选项卡中的出路,因此如果列在交叉表中超出,则它们不应该在下一页上进行.否则新的交叉表应该在第一个之后重复.
例如,交叉表中会显示两列:

现在,如果添加了一个新列,并假设它无法在给定的页面宽度限制内容纳,则默认情况下它将转到CR旁边的页面.
但是在我的报告中,它需要显示在第一个交叉表下面(而不是在下一页),它将如下所示:

如果有出路,请建议我:)
提前致谢
我有两种情况需要将Sql中的DateTime字段设置为null.我使用C#和LINQ to SQL Classes.我读了很多关于stackoverflow的问题,这些问题就像我的问题一样,但我还是把它给了我一点不同.
当我们插入新客户时.
对应代码:
Customer customer = new Customer();
customer.CustomerName = txt_name.Text;
customer.DOB = dtp_dob.Checked ? DateTime.Parse(dtp_dob.Value.ToString("yyyy-MM-dd")) : //send null here;
Run Code Online (Sandbox Code Playgroud)
customer.DOB是System.DateTime.
我尝试的是:
1)
customer.DOB = dtp_dob.Checked ? DateTime.Parse(dtp_dob.Value.ToString("yyyy-MM-dd")) : SqlDateTime.Null;
Run Code Online (Sandbox Code Playgroud)
但是这不会成功,因为SqlDateTime无法转换为System.DateTime.
2)
DateTime? nullDateTime = new DateTime();
customer.DOB = dtp_dob.Checked ? DateTime.Parse(dtp_dob.Value.ToString("yyyy-MM-dd")) : nullDateTime.Value
Run Code Online (Sandbox Code Playgroud)
在这种情况下,构建成功但它将抛出SqlDateTime溢出异常.
那么如何传递null值
LINQ数据类中DOB成员的属性

他们中的许多人建议将"自动生成值"设置为true,而不是插入任何值.没错,它适用于插入案例.
但现在假设已经存在一个客户条目,其中某个日期时间值设置为DOB字段.现在用户想要清除这个值(删除生日),然后在这种情况下我必须使用UpdateOn传递一个空值来清除相应客户行中的日期时间.
非常感谢你提前:)
我ListView里面有一个控件UserControl.但是当内容溢出的大小时,尽管在XAML中设置了ListViewvertical ScrollBar,但仍未启用vertical .

XAML如下所示:
<UserControl x:Class="GrandSuccessProject.View.ContactsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="367" d:DesignWidth="548" Background="{x:Null}" VerticalContentAlignment="Top">
<ListView ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ItemsSource="{Binding SelectedContacts}"
ItemContainerStyle="{StaticResource ContainerStyle}"
Grid.Row="1"
VerticalAlignment="Top"
VerticalContentAlignment="Top" />
</UserControl>
Run Code Online (Sandbox Code Playgroud)
我也尝试将ListView内部分组ScrollViewer,但仍然无法正常工作.
非常感谢你提前:)
关于卸载Windows服务,我们对stackoverflow有很多疑问.
尝试了所有这些后,我仍然无法在新版本的安装上卸载Windows服务.
我使用安装和部署项目来安装/卸载我的项目,该项目有一个Windows服务和一些其他项目.
在安装较新版本的过程中,所有其他项目都已成功重新安装,但Windows服务项目无法重新安装,并说:
错误1001:指定的服务已存在.
我引用了此链接并尝试将代码添加到我的安装自定义操作以停止服务.如果我正确理解了这个链接的答案,我已经把代码停在服务的projectInstaller.cs文件中的服务:
public override void Install(IDictionary stateSaver)
{
ServiceController sc = new ServiceController("SareeManagerNotifications");
if (sc.Status == ServiceControllerStatus.Running)
sc.Stop();
base.Install(stateSaver);
}
Run Code Online (Sandbox Code Playgroud)
自定义操作窗格如下所示:

突出显示的部分是服务.
我也经历了这个答案,它说将自定义动作条件设置为NOT PREVIOUSVERSIONSINSTALLED.

这对我不起作用.我哪里错了?
提前致谢 :)
c# ×8
.net ×5
linq ×2
linq-to-sql ×2
serial-port ×2
sql ×2
c++ ×1
datetime ×1
directx ×1
exception ×1
installer ×1
listview ×1
null ×1
phone-call ×1
report ×1
reporting ×1
scrollview ×1
sql-server ×1
vb.net ×1
wpf ×1
xaml ×1