Tag: C#的

从服务启动用户会话中的进程

在Windows Vista / 7/2008 / 2008R2中,是否可以通过服务在用户会话中启动进程? 具体来说,本地会话将是最有用的。 我一直在读的东西似乎是说这是不可能的,但我想我会在完全放弃之前问这里。 我在VB.NET编码,但会采取任何build议。

GMail SMTP通过所有端口上的C#.Net错误

我一直在为此而努力,迄今一直在悲惨地失败。 我最近的尝试是从这个堆栈代码中解除的: 使用C#通过Gmail SMTP服务器发送电子邮件 ,但是我尝试了所有可以在堆栈和其他地方find的语法。 我的代码目前是: var client = new SmtpClient("smtp.gmail.com", 587) { Credentials = new NetworkCredential("me@gmail.com", "mypass"), EnableSsl = true }; client.Send("me@gmail.com","me@gmail.com","Test", "test message"); 运行该代码给我一个立即的exception“发送邮件失败”,它有一个“无法连接到远程服务器”的内联。 如果我将端口更改为465(正如gmail文档所build议的那样),我每次都会收到一个超时。 我读过465不是一个很好的端口,所以我想知道这个交易是怎样的,让我失败了。 我的用户和通行证是正确的。 我读过,我必须有POP服务设置在我的Gmail帐户,所以我做到了。 徒劳无功。 我本来是试图让我的品牌GMail帐户工作,但遇到相同的问题后,我认为去我的常规Gmail帐户会更容易…到目前为止,情况并非如此。 谢谢您的帮助。 保罗

如何打开PDF文件在一个新的选项卡或窗口,而不是下载(使用asp.net)?

这是下载文件的代码。 System.IO.FileStream fs = new System.IO.FileStream(Path+"\\"+fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read); byte[] ar = new byte[(int)fs.Length]; fs.Read(ar, 0, (int)fs.Length); fs.Close(); Response.AddHeader("content-disposition", "attachment;filename=" + AccNo+".pdf"); Response.ContentType = "application/octectstream"; Response.BinaryWrite(ar); Response.End(); 当这个代码被执行时,它会要求用户打开或保存文件。 而不是我需要打开一个新的选项卡或窗口,并显示该文件。 我怎样才能做到这一点? 注意: 文件不需要位于网站文件夹中。 它可能位于其他文件夹中。

audio输出与video处理与opencv

我正在使用opencv处理video,但同时我需要播放audio并对其进行简单的控制,比如大声或当前帧数。 我想我应该用ffmpeg创build一个并行的进程,但是我不知道该怎么做。 你能解释一下该怎么办? 或者你知道另一个解决scheme?

在.NET中从NetworkStream读取的正确方法是什么?

我一直在为此而苦苦挣扎,无法find我的代码无法正确读取我写的TCP服务器的原因。 我正在使用TcpClient类和它的GetStream()方法,但没有按预期工作。 无论是操作块无限期(最后一次读取操作没有按预期超时),或数据被裁剪(出于某种原因,读取操作返回0并退出循环,也许服务器没有足够快的响应)。 这是实现这个function的三个尝试: // this will break from the loop without getting the entire 4804 bytes from the server string SendCmd(string cmd, string ip, int port) { var client = new TcpClient(ip, port); var data = Encoding.GetEncoding(1252).GetBytes(cmd); var stm = client.GetStream(); stm.Write(data, 0, data.Length); byte[] resp = new byte[2048]; var memStream = new MemoryStream(); […]

C#如何在继续之前等待网页完成加载

我正在尝试创build一个程序,通过我们的缺陷跟踪系统的Web界面一次克隆多个错误。 如何在页面完全加载之前等待,然后继续? //This is pseudo code, but this should give you an idea of what I'm trying to do. The //actual code uses multi-threading and all that good stuff :). foreach (string bug in bugs) { webBrowser.Navigate(new Uri(url)); webBrowser.Document.GetElementById("product").SetAttribute("value", product); webBrowser.Document.GetElementById("version").SetAttribute("value", version); webBrowser.Document.GetElementById("commit").InvokeMember("click"); //Need code to wait for page to load before continuing. }

压缩HTTP GET响应

我目前正在将less数MVC3控制器迁移到MVC4 Api控制器。 我已经实现了MVC3控制器Get方法响应的压缩机制,通过embeddedActionFilterAttribute并重写OnActionExecutiong方法。 经过一番研究,我发现我需要使用System.Web.HttpFilters ActionFilterMethod 。 如果有人能够共享一段示例代码来让我开始使用GZip压缩HTTP响应,那将是非常好的

asynchronous实现IValueConverter

如果我想在一个IValueConverter内部触发asynchronous方法。 有没有更好的等待,然后强制它通过调用结果属性同步? public async Task<object> Convert(object value, Type targetType, object parameter, string language) { StorageFile file = value as StorageFile; if (file != null) { var image = ImageEx.ImageFromFile(file).Result; return image; } else { throw new InvalidOperationException("invalid parameter"); } }

以编程方式将图像添加到RTF文档

我正在尝试将图像添加到正在创build的RTF文档中。 我宁愿不使用清除剪贴板的“复制/粘贴”方法(涉及在RichTextBox中粘贴图像,然后访问.RTF属性)(因为这对我的最终用户来说是一个麻烦和困惑)。 我到目前为止的代码返回需要被插入到RTF文档来打印图像的string。 input的图像(位于$path)通常是BMP或JPEG格式,但在这个阶段,我不关心如何将图像存储在RTF中,只有我可以得到它的工作。 public string GetImage(string path, int width, int height) { MemoryStream stream = new MemoryStream(); string newPath = Path.Combine(Environment.CurrentDirectory, path); Image img = Image.FromFile(newPath); img.Save(stream, System.Drawing.Imaging.ImageFormat.Png); byte [] bytes = stream.ToArray(); string str = BitConverter.ToString(bytes, 0).Replace("-", string.Empty); //string str = System.Text.Encoding.UTF8.GetString(bytes); string mpic = @"{\pict\pngblip\picw" + img.Width.ToString() + @"\pich" + img.Height.ToString() + […]

何时使用ReleaseComObject vs FinalReleaseComObject?

什么时候应该使用Marshal.FinalReleaseComObject vs Marshal.ReleaseComObject ? 使用Marshal.FinalReleaseComObject有没有危险?